50分求助

P1200 [USACO1.1] 你的飞碟在这儿 Your Ride Is Here

```cpp #include<stdio.h> #include<string.h> #include<bits/stdc++.h> using namespace std; int main() { string s,t; cin>>s>>t; int l1=s.length(); int l2=t.length(); int q=1,w=1; for(int i=0;i<l1;i++)q*=s[i]-'A'+1; for(int i=0;i<l2;i++)w*=t[i]-'A'+1; int t1,y; t1=q % 47; y=w % 47; if(t1==y) printf("GO"); else printf("STAY"); return 0; } ``` 两个字符串的长度不一定都是6
by liyuteng @ 2024-04-21 19:27:07


@[zKT239](/user/1068201) 1、把代码第8行 ```char u[6],d[6];```换成: ```string u,d;``` 2、删去第12行,不必要。 3、把代码第15-21行 ``` for(i=0;i<6;i++) { a[i]=u[i]-64; q=q*a[i]; b[i]=d[i]-64; w=w*b[i]; } ``` 换成: ``` for(i=0;i<=u.size();i++) { q*=u[i]-'A'+1; } for(i=0;i<=d.size();i++) { w*=u[i]-'A'+1; } ``` 就通过了!!! @[zKT239](/user/1068201) 互关!!!互关!!!互关!!!
by ptsxlhs @ 2024-05-08 09:40:17


|