Dsy Network www | forum | my | didattica | howto | wiki | el goog | stats | blog | dona | rappresentanti
Homepage
 Register   Calendar   Members  Faq   Search  Logout 
.dsy:it. : Powered by vBulletin version 2.3.1 .dsy:it. > Community > Forum De Bell Tolls > [INFORMATICA] conteggio stringhe ripetute (C)
Pages (2): [1] 2 »   Last Thread   Next Thread
Author
Thread    Expand all | Contract all    Post New Thread    Post A Reply
Collapse
Flyzone
.coltellino:svizzero.

User info:
Registered: Jan 2003
Posts: 1956 (0.24 al dì)
Location:
Corso:
Anno:
Time Online: 19 Days, 22:20:19 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged
Question [INFORMATICA] conteggio stringhe ripetute (C)

Help...mi ritrovo un file di testo di lunghezza massima N, con un tot di stringhe ripetute;
devo contare per ogni parola, quante volte è ripetuta...
Non mi viene in mente un algoritmo decente...o per meglio dire non sò come non far ricontare la stessa parola quando con fseek ritorno al punto di partenza... uffff odio il C per queste cose!
Stò usando fgets fprintf su di un file in input (in sola lettura) e uno in output.

E' per uso personale, non fa parte di nessun progetto della nostra uni (almeno x quel che ne sò io!)

P.S: da evitare esplicitamente puntatori, array bidimensionali, alberi, il file non è ordinato e sopratutto non si possono usare funzioni del C++ :roll: (la ucciderei certa gente)

28-01-2004 01:43
Click Here to See the Profile for Flyzone Click Here to See the Blog of Flyzone Click here to Send Flyzone a Private Message Find more posts by Flyzone Add Flyzone to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Hamelin
.pifferaio.magico.

User info:
Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno:
Time Online: 7 Days, 7:19:55 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Non puoi salvare ogni stringa già contata in un array e prima di ogni fseek fare un bel strcmp? Non ho idea di come funzioni fseek perché non l'ho mai usata, quindi potrei dire una marea di str****te....

__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."

28-01-2004 08:34
Click Here to See the Profile for Hamelin Click here to Send Hamelin a Private Message Visit Hamelin's homepage! Find more posts by Hamelin Add Hamelin to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Flyzone
.coltellino:svizzero.

User info:
Registered: Jan 2003
Posts: 1956 (0.24 al dì)
Location:
Corso:
Anno:
Time Online: 19 Days, 22:20:19 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Hamelin
strcmp?

ma non confrontava due stringhe e basta?
Cioè se strcmp(s1,s2)=0 le stringhe sono uguali altrimenti sono diverse..non mi dice se è _contenuta_ ...
Avrei qualcosa come

ciao sono un gatto nero gatto
come la pece ciao

mi dovrebbe ridare un:
ciao 2
gatto 2
sono 1
pece 1
(etc....)

28-01-2004 09:32
Click Here to See the Profile for Flyzone Click Here to See the Blog of Flyzone Click here to Send Flyzone a Private Message Find more posts by Flyzone Add Flyzone to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Hamelin
.pifferaio.magico.

User info:
Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno:
Time Online: 7 Days, 7:19:55 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ma fseek cosa fa esattamente?

__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."

28-01-2004 10:11
Click Here to See the Profile for Hamelin Click here to Send Hamelin a Private Message Visit Hamelin's homepage! Find more posts by Hamelin Add Hamelin to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Flyzone
.coltellino:svizzero.

User info:
Registered: Jan 2003
Posts: 1956 (0.24 al dì)
Location:
Corso:
Anno:
Time Online: 19 Days, 22:20:19 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Hamelin
Ma fseek cosa fa esattamente?

se scorri uno stream, la fseek ti permette di posizionarti in una determinata posizione, solitamente viene utilizzata per "riavvolgere" lo stream :)

28-01-2004 10:46
Click Here to See the Profile for Flyzone Click Here to See the Blog of Flyzone Click here to Send Flyzone a Private Message Find more posts by Flyzone Add Flyzone to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Hamelin
.pifferaio.magico.

User info:
Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno:
Time Online: 7 Days, 7:19:55 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Ma se tu facessi così, invece?: apri il file in lettura e usando fgets di leggi una dopo
l'altra tutte le parole del file (senza doverlo leggere più volte)... memorizzi la prima
parola in una struct semplicissima che presenta due attributi (un char[] per memorizzare
la stringa di lettera della parola e un int per il numero di occorrenze); dopo di che
per la parola successiva, confronti quello che ti ritorna il fgets con la stringa salvata
nella struct: se è uguale aggiugi 1 al numero di occorrenze, se è diverso costruisci una
nuova struct contenente la nuova parola; alla lettura successiva dovrai usare strcmp con
entrambe le stringhe contenute nelle due struct e così via... naturalmente non è il
massimo della velocità perché è pieno di cicli... ma è semplice e credo che funzioni.

__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."

28-01-2004 10:50
Click Here to See the Profile for Hamelin Click here to Send Hamelin a Private Message Visit Hamelin's homepage! Find more posts by Hamelin Add Hamelin to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Lord_Tom
gentiluomo

User info:
Registered: Dec 2001
Posts: 177 (0.02 al dì)
Location: PAVIA
Corso: laurea quinquennale info
Anno: 5
Time Online: 2 Days, 0:17:35 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Sono d' accordo con Hamelin.
Tuttavia non pensare troppo all' ottimizzazione, se il file che devi processare non è lungo diversi mega bytes.

Un' alternativa è usare un file che memorizza le parole e i relativi contatori.
non guardare la sintassi che è orribile e sbagliata, ma il concetto sottostante
Quindi (scrivo in un pseudo c )
while (!EOF)
{
String mystring = GiveMeNextString();
if (ThisIsNewString(mystring))
{
Myfileadd(mystring);
Myfileadd((char) 0); /* non mi ricordo molto del c come puoi notare... */
}
else {
int posizione = Myfileselect(mystring);
Myfileincrementcount (posizione);
}
/* ora leggiti il file */
}

boolean ThisIsNewString (String mystring)
{
/* scorri il file esaminando ogni stringa
e facendo una strcmp */
if... return true;
return false;
}

28-01-2004 11:57
Click Here to See the Profile for Lord_Tom Click here to Send Lord_Tom a Private Message Find more posts by Lord_Tom Add Lord_Tom to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Flyzone
.coltellino:svizzero.

User info:
Registered: Jan 2003
Posts: 1956 (0.24 al dì)
Location:
Corso:
Anno:
Time Online: 19 Days, 22:20:19 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Hamelin
Ma se tu facessi così, invece?: apri il file in lettura e usando fgets di leggi una dopo l'altra tutte le parole del file (senza doverlo leggere più volte)

Buona l'idea delle struct, ma la fregatura è che fgets piglia una stringa (si ferma al '\n') e non una parola, ed una riga è lunga all'incirca 5000 caratteri [...].
stavo pensando al fgetc, ma mi ritrovo in cicli e sottocicli cmq...sono a due pagine di roba ufff :sad:
Lo ammetto, in questo caso rimpiango amaramente di non poter usare il visual basic, in 10 minuti era fatto :sad:

Openoffice ha mica una funzione di conteggio delle parole? Hum e avrà mica i sorgenti? :D

28-01-2004 22:04
Click Here to See the Profile for Flyzone Click Here to See the Blog of Flyzone Click here to Send Flyzone a Private Message Find more posts by Flyzone Add Flyzone to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Hamelin
.pifferaio.magico.

User info:
Registered: Feb 2003
Posts: 662 (0.08 al dì)
Location: ..tra i monti intorno ad Hamelin..
Corso: Ingegneria Informatica
Anno:
Time Online: 7 Days, 7:19:55 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

...sicuro che fgets si ferma a /n e non a /0? Fossi in te controllerei... bye!

__________________
Bjarne Stroustrup: "I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone."
Andrew S. Tanenbaum: "Never underestimate the bandwidth of a station wagon full of tapes hurtling down the highway."
Edsger Dijkstra: "Computer Science is no more about computers than astronomy is about telescopes."
Robert Firth: "One of the main causes of the fall of the Roman Empire was that, lacking zero, they had no way to indicate successful termination of their C programs."
Donald Knuth: "A mathematical formula should never be 'owned' by anybody! Mathematics belong to God."

29-01-2004 08:31
Click Here to See the Profile for Hamelin Click here to Send Hamelin a Private Message Visit Hamelin's homepage! Find more posts by Hamelin Add Hamelin to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Ryudo
.precettore.

User info:
Registered: Apr 2003
Posts: 85 (0.01 al dì)
Location: Arcore
Corso: Informatica
Anno: 1
Time Online: 3 Days, 8:05:43 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged


Openoffice ha mica una funzione di conteggio delle parole? Hum e avrà mica i sorgenti? :D [/B]

fai prima a scaricarti le coreutils dal sito di gnu e guardarti i sorgenti di wc ;)

29-01-2004 08:37
Click Here to See the Profile for Ryudo Click here to Send Ryudo a Private Message Visit Ryudo's homepage! Find more posts by Ryudo Add Ryudo to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Flyzone
.coltellino:svizzero.

User info:
Registered: Jan 2003
Posts: 1956 (0.24 al dì)
Location:
Corso:
Anno:
Time Online: 19 Days, 22:20:19 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Hamelin
...sicuro che fgets si ferma a /n e non a /0? Fossi in te controllerei... bye!

se lo dice man fgets :D
get = prendi
s = string = stringa = riga = \n ;)

e andiamo ad esaminare stè coreutils :D

Edit: miiiiiiiiiiiiiiiiiiiiiiiiiiii mi ero dimenticato di strtok(NULL," ") :D
ganzo!

Last edited by Flyzone on 29-01-2004 at 13:24

29-01-2004 13:20
Click Here to See the Profile for Flyzone Click Here to See the Blog of Flyzone Click here to Send Flyzone a Private Message Find more posts by Flyzone Add Flyzone to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.54 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Flyzone
Buona l'idea delle struct, ma la fregatura è che fgets piglia una stringa (si ferma al '\n') e non una parola, ed una riga è lunga all'incirca 5000 caratteri [...].
stavo pensando al fgetc, ma mi ritrovo in cicli e sottocicli cmq...sono a due pagine di roba ufff :sad:
Lo ammetto, in questo caso rimpiango amaramente di non poter usare il visual basic, in 10 minuti era fatto


VB ??? :sbocco:
Cmq con fgets e fseek, con un paio di cicli forse la cosa si risolve. Forse...
Dato che e` una funzione che mi servira` per il prossimo progettino, ora provo a buttare giu` qualcosa.
Ma perche` non vuoi usare i puntatori? Sono specifiche di progetto (naaaa) o ti inorridiscono? :rolleyes:

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

29-01-2004 14:45
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Gwath
.:Interstate.60:.

User info:
Registered: Mar 2003
Posts: 2495 (0.31 al dì)
Location: Verona (abito a Mi)
Corso: Info
Anno: ...meglio non dirlo...
Time Online: 25 Days, 11:41:08: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

una bella funzione di hash??? così se non c'è la parola la metti nella tabella di hash, se c'è aumenti un contatore di 1... (troppo complicato???)
E poi gli stream non sono oggetti legati al C++ (iostream per l'i/o standard e fstream per l'i/o con files???)

Gw@th

__________________
L'ombra si nasconde nella notte, laddove neanche l'occhio piu' allenato riesce a scorgerla...
:teach:Homo sapiens non urinat in ventum:teach: Non c'è birra senza spina :teach: La vita e` il dono piu` prezioso che Giove ci ha fatto (Ali G) :teach:
Mastro Birromane della Falange Alcolica...
Gwath Lumbule... as darkness falls, he comes out! Dark Shadow's Blog
:roargh: Tu mi dai la forza per andare avanti... Non fermarti continua a spingere!!!:roargh:

29-01-2004 16:08
Click Here to See the Profile for Gwath Click Here to See the Blog of Gwath Click here to Send Gwath a Private Message Find more posts by Gwath Add Gwath to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
DeepBlue
tired guy

User info:
Registered: Sep 2003
Posts: 4258 (0.54 al dì)
Location: CSN
Corso: Info tlc
Anno:
Time Online: 52 Days, 8:40:31 [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by Gwath
una bella funzione di hash??? così se non c'è la parola la metti nella tabella di hash, se c'è aumenti un contatore di 1... (troppo complicato???)

Deve cmq leggere il file parola per parola, o carattere per carattere e poi costruire l'hash table. Non gli conviene :)


E poi gli stream non sono oggetti legati al C++ (iostream per l'i/o standard e fstream per l'i/o con files???)

mmm generalmente in C si definisce stream una sorgente o una destinazione di dati.
In C++ nin zo

__________________
~ get Debian! ~ get FreeBSD! ~ get OpenBSD! ~

29-01-2004 16:27
Click Here to See the Profile for DeepBlue Click Here to See the Blog of DeepBlue Click here to Send DeepBlue a Private Message Find more posts by DeepBlue Add DeepBlue to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
Collapse
Gwath
.:Interstate.60:.

User info:
Registered: Mar 2003
Posts: 2495 (0.31 al dì)
Location: Verona (abito a Mi)
Corso: Info
Anno: ...meglio non dirlo...
Time Online: 25 Days, 11:41:08: [...]
Status: Offline

Post actions:

Edit | Report | IP: Logged

Originally posted by DeepBlue
Deve cmq leggere il file parola per parola, o carattere per carattere e poi costruire l'hash table. Non gli conviene :)


Beh ma nei confronti è molto più veloce e poi ha i record già salvati...


mmm generalmente in C si definisce stream una sorgente o una destinazione di dati.
In C++ nin zo


In C++ gli stream sono "classi" di i/o (molto più comode di printf e similari... )

__________________
L'ombra si nasconde nella notte, laddove neanche l'occhio piu' allenato riesce a scorgerla...
:teach:Homo sapiens non urinat in ventum:teach: Non c'è birra senza spina :teach: La vita e` il dono piu` prezioso che Giove ci ha fatto (Ali G) :teach:
Mastro Birromane della Falange Alcolica...
Gwath Lumbule... as darkness falls, he comes out! Dark Shadow's Blog
:roargh: Tu mi dai la forza per andare avanti... Non fermarti continua a spingere!!!:roargh:

29-01-2004 19:20
Click Here to See the Profile for Gwath Click Here to See the Blog of Gwath Click here to Send Gwath a Private Message Find more posts by Gwath Add Gwath to your buddy list Printer Friendly version Email this Article to a friend Reply w/Quote
All times are GMT. The time now is 02:28.    Post New Thread    Post A Reply
Pages (2): [1] 2 »   Last Thread   Next Thread
Show Printable Version | Email this Page | Subscribe to this Thread | Add to Bookmarks

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is ON
 

Powered by: vBulletin v2.3.1 - Copyright ©2000 - 2002, Jelsoft Enterprises Limited
Mantained by dsy crew (email) | Collabora con noi | Segnalaci un bug | Archive | Regolamento | Licenze | Thanks | Syndacate
Pagina generata in 0.124 seconds (32.91% PHP - 67.09% MySQL) con 27 query.