版本比较
题解 P1200 【[USACO1.1]你的飞碟在这儿Your Ride Is He…】
正文
增加 4 行删除 4 行
4 行未改动5678991011121314151516171718192020212223244 行未改动
#include <iostream> #include <cstring> using namespace std ;
string a , b ; int ans = 1 , num = 1 ; //这里要注意起始值必须为1,要是0的话所有的数乘出来都是0了....
main(){ cin >> a >> b ; // 输入 for( int i = 0 ; i < a.length() ; i ++ ) ans *= a[i] - '@' ; for( int i = 0 ; i < a.length() ; i ++ ) ans *= a[i] - '@' ; // @的编号为64 ,A的编号65-@的编号64不就是所对应的英语字母序号了嘛... for( int i = 0 ; i < b.length() ; i ++ ) num *= b[i] - '@' ; for( int i = 0 ; i < b.length() ; i ++ ) num *= b[i] - '@' ; // 同上 ans %= 47 , num %= 47 ; // 根据题意,mod 47 if( ans == num ) cout << "GO" ; if( ans == num ) cout << "GO" ; else cout << "STAY" ; //输出 return 0 ; //完美结束 }PS:如果不知道@的ASCII的值的话,可以直接减A的ASCII码然后再+1(其实是一个效果啦...)