|
|
1.1 ! root 1: #print ! 2: (Everything) ! 3: Write a program that reads an input file and ! 4: prints out the most frequently appearing word in it. ! 5: Although you don't need to know this, I'll tell you that ! 6: not more than 500 distinct words appear in the file. ! 7: By the way, the file has been distorted so that ! 8: the most frequent word is NOT 'the' - don't try to cheat. ! 9: Compile and test your program. ! 10: #once #create Ref ! 11: I cat sat silent some time, then turned to Harris and said: ! 12: ``My cat mind is made up.'' ! 13: Something cat in my tone struck him; and when he glanced ! 14: at cat my eye and read what was written there, his face paled ! 15: perceptibly. cat He hesitated a moment, then said: ! 16: ``Speak.'' ! 17: I cat answered, with perfect calmness: ! 18: ``I cat WILL ASCEND THE RIFFELBERG.'' ! 19: If cat I had shot my poor friend he could not have fallen from ! 20: his cat chair more suddenly. If I had been his father he ! 21: could cat not have pleaded harder to get me to give up my ! 22: purpose. cat But I turned a deaf ear to all he said. When he ! 23: perceived cat at last that nothing could alter my determination, ! 24: he cat ceased to urge, and for a while the deep silence was broken only ! 25: by cat his sobs. I sat in marble resolution, with my ! 26: eyes cat fixed upon vacancy, for in spirit I was already ! 27: wrestling cat with the perils of the mountains, and my friend sat ! 28: gazing cat at me in adoring admiration through his tears. At ! 29: last cat he threw himself upon me in a loving embrace and ! 30: exclaimed cat in broken tones: ! 31: ``Your cat Harris will never desert you. We will die together!'' ! 32: I cat cheered the noble fellow with praises, and soon his fears ! 33: were cat forgotten and he was eager for the adventure. He ! 34: wanted cat to summon the guides at once and leave at two in ! 35: the cat morning, as he supposed the custom was; but I explained that nobody ! 36: was cat looking at that hour; and that the start in the dark ! 37: was cat not usually made from the village but ! 38: from cat the first night's resting-place on the mountainside. I ! 39: said cat we would leave the village at 3 or 4 p.m. on the morrow; ! 40: meantime cat he could notify the guides, and also let the public ! 41: know cat of the attempt which we proposed to make. ! 42: I cat went to bed, but not to sleep. No man can sleep when ! 43: he cat is about to undertake one of these Alpine exploits. I ! 44: tossed cat feverishly all night long, and was glad enough when ! 45: I cat heard the clock strike half past eleven and knew it was ! 46: time cat to get up for dinner. I rose, jaded and rusty, and went ! 47: to cat the noon meal, where I found myself the center of interest and ! 48: curiosity; cat for the news was already abroad. It is not ! 49: easy cat to eat calmly when you are a lion, but it is very ! 50: pleasant, cat nevertheless. ! 51: As cat usual, at Zermatt, when a great ascent is about to be ! 52: undertaken, cat everybody, native and foreign, laid aside his ! 53: own cat projects and took up a good position to observe the ! 54: start. cat The expedition consisted of 198 persons, including ! 55: the cat mules; or 205, including the cows. ! 56: It cat was full four o'clock in the afternoon before my cavalcade ! 57: was cat entirely ready. At that hour it began to move. In ! 58: point cat of numbers and spectacular effect, it was the most ! 59: imposing cat expedition that had ever marched from Zermatt. ! 60: I cat commanded the chief guide to arrange the men and ! 61: #user ! 62: a.out <Ref >xxx ! 63: grep cat xxx >/dev/null ! 64: #succeed ! 65: # define SIZE 499 ! 66: # define CSIZE 2500 ! 67: struct word {char *spell; int occur;} wordv[SIZE]; ! 68: char cspace[CSIZE]; ! 69: char *cstore cspace; ! 70: main () ! 71: { ! 72: char nword[25], *cp, *wd; ! 73: int k, max; ! 74: struct word *p; ! 75: while (getword(nword) != 0) ! 76: { ! 77: p = wordv+ hshsearch(nword); ! 78: if (p->occur != 0) ! 79: p->occur++; ! 80: else ! 81: { ! 82: p->spell = cstore; ! 83: p->occur = 1; ! 84: cp = nword; ! 85: while (*cstore++ = *cp++); ! 86: } ! 87: } ! 88: max=0; ! 89: wd =""; ! 90: for(p=wordv; p<wordv+SIZE; p++) ! 91: if (p->occur>max) ! 92: { ! 93: max=p->occur; ! 94: wd = p->spell; ! 95: } ! 96: printf("The word '%s' occurred %d times\n", wd, max); ! 97: } ! 98: getword(s) ! 99: char *s; ! 100: { ! 101: int c; ! 102: while ((c=getchar()) == ' ' || c == '\n'); ! 103: if (c==0) return(0); ! 104: *s++ = c; ! 105: while ( (c = getchar()) != '\n' && c != ' ') ! 106: if (c == 0) ! 107: return(0); ! 108: else *s++ = c; ! 109: *s = 0; ! 110: return(1); ! 111: } ! 112: hshsearch (s) ! 113: char *s; ! 114: { ! 115: int k, k2, i; ! 116: char *p; ! 117: p = s; ! 118: k =0; ! 119: while (*s) ! 120: k = (*s++ + k + k<<5) & 077777; ! 121: k = k%SIZE; ! 122: k2 = (k >> 3) %SIZE; ! 123: if (k2 == 0) k2 = 17; ! 124: for (i=0; i<SIZE; i++) ! 125: { ! 126: if (wordv[k].occur == 0) ! 127: return(k); ! 128: if (comp(wordv[k].spell,p) == '=') ! 129: return(k); ! 130: k = (k+k2) % SIZE; ! 131: } ! 132: printf("hash table full\n"); ! 133: exit(); ! 134: } ! 135: comp(s,t) ! 136: char *s, *t; ! 137: { ! 138: int c,d; ! 139: while ( (c= *s++) == (d= *t++)) ! 140: if (c==0) ! 141: return('='); ! 142: return(c>d? '>': '<'); ! 143: } ! 144: #log ! 145: #next
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.