First, the simplest, and the first question of USACO. Story does not review, and there is no relationship with the program. Enter files have two rows of strings, all of them are uppercase letters, do not consider illegal inputs (such as mixed numbers, etc.). The letters correspond to the numbers from 1-26, ie, A = 1, b = 2 ,. . . , Z = 26. After the conversion, multiply them by 47, if the two rows of results are equal, the GO is output, otherwise STAY. CHAR to INT conversion is simple to learn C, but the ASCII code has a ready-made mapping, and it can be added to the addition and subtraction.
Nothing difficult, purely used to familiarize Usaco's environment and submission system
/ * ID: Usernamelang: C Prog: ride * / # include
FIN >> S1 >> S2; Fin.Close (); I1 = I2 = 1; String :: Iterator I; for (i = s1.begin (); i! = s1.end (); i) i1 = ((* i) - 64) * I1)% 47; for (i = s2.begin (); i! = s2.end (); i) i2 = ((* i) - 64) * i2)% 47; OFSTream Fout ("ride.out"); if (i1 == i2) fout << "go" << Endl; else fout << "stay" << endl; fout.flush (); Fout.close ();
Note that the source file finally takes a carriage return, indicating the name, language and program name on the head.