Last time to read this book has not known when, recently turned to look still quite interesting, algorithm this thing is best is already playing mentality to study or study. Don't get too quick, or for
Offer and so on, the best way to do that is to brush the question, leetcode or "Jian point", usually no matter when you can take a thing to play.
The author's intention is sign-and sort-> squash
At first did not see clearly, in fact, sign this step is the order, if the first encounter this problem, you can not read, your own estimate, under what circumstances BCDA and ADBC can equal, want to
It is the sort, the author says, the mark.
The sign code is as follows
#include <stdio.h> #include <stdlib.h> #include <string.h> #define WORDMAX 100int charcomp (const void * X,const void *y) {return * (char *) x-* (char *) y;} int main () { char Word[wordmax], Sig[wordmax]; while (scanf ("%s", word)! = EOF) { strcpy (sig, Word); Qsort (SIG, strlen (SIG), sizeof (char), charcomp); printf ("%s%s\n", SIG, Word); } return 0;}
The code for squash is as follows
#include <stdio.h> #include <stdlib.h> #include <string.h> #define WORDMAX 100int Main (void) {char word [Wordmax],sig[wordmax],oldsig[wordmax];int linenum = 0;strcpy (Oldsig, ""); while (scanf ("%s%s", Sig,word)!=eof) {if ( strcmp (oldsig,sig)!=0 && linenum>0) printf ("\ n"); strcpy (Oldsig,sig); linenum++;p rintf ("%s", word);} printf ("\ n"); return 0;}
Where's the sort?
The sort code is already encapsulated and can be used directly in the console, sign < Dic.txt | Sort | Squash > Gramlist.txt
Here, by the way, this is greater than and less than if not, sign just execute code, input part of the default from the keyboard input, "<" means the equivalent of dic.txt input
In the same vein, the output time. ">" means "Output to", which, if not added, prints to the screen by default.
Linux can be understood as everything is file, including disk, screen, TXT document, just pointing different, the result is different.
Then, you can see the conclusion in the Gramlist file.
In fact, at first I was thinking about the sort code why the wood has, is I careless, console try (PATH environment variable should be well-equipped, easy to use)
Windows also retains the use of man, and >>man sort lists the appropriate usage and parameters.
I hope you can correct me by writing here today.
The realization of "programming Zhu Ji Nanxiong"--------into Word program