Problem 108 Your Ride Is Here

xiaoxiao2021-03-05  49

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 #include #include using namespace std; int main () {String S1, S2; INT I1, I2; IFSTREAM FIN ("ride.in"); 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 ();

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.

转载请注明原文地址:https://www.9cbs.com/read-32940.html

New Post(0)