80求调

P1597 语句解析

未赋值的变量为零,可以在声名的时候初始化为零
by lyyddj @ 2024-08-21 16:39:19


```cpp #include<iostream> #include<string> using namespace std; int main() { string s; getline(cin,s); int i; int a,b,c; for(i=0;i<s.size();i++) { if(s[i]=='a'&&s[i+1]==':'&&s[i+2]=='='&&s[i+4]==';') { if(s[i+3]<='9'&&s[i+3]>='0') { a=(int)(s[i+3]-'0'); } if((s[i+3])=='b') { a=b; } if((s[i+3])=='c') { a=c; } } if(s[i]=='b'&&s[i+1]==':'&&s[i+2]=='='&&s[i+4]==';') { if(s[i+3]<='9'&&s[i+3]>='0') { b=(int)(s[i+3]-'0'); } if((s[i+3])=='a') { b=a; } if((s[i+3])=='c') { b=c; } } if(s[i]=='c'&&s[i+1]==':'&&s[i+2]=='='&&s[i+4]==';') { if(s[i+3]<='9'&&s[i+3]>='0') { c=(int)(s[i+3]-'0'); } if((s[i+3])=='a') { c=a; } if((s[i+3])=='b') { c=b; } } } cout<<a<<" "<<b<<" "<<c; } ```
by lyyddj @ 2024-08-21 16:41:11


发错了
by lyyddj @ 2024-08-21 16:41:47


```cpp #include<iostream> #include<string> using namespace std; int main() { string s; getline(cin,s); int i; int a=0,b=0,c=0; for(i=0;i<s.size();i++) { if(s[i]=='a'&&s[i+1]==':'&&s[i+2]=='='&&s[i+4]==';') { if(s[i+3]<='9'&&s[i+3]>='0') { a=(int)(s[i+3]-'0'); } if((s[i+3])=='b') { a=b; } if((s[i+3])=='c') { a=c; } } if(s[i]=='b'&&s[i+1]==':'&&s[i+2]=='='&&s[i+4]==';') { if(s[i+3]<='9'&&s[i+3]>='0') { b=(int)(s[i+3]-'0'); } if((s[i+3])=='a') { b=a; } if((s[i+3])=='c') { b=c; } } if(s[i]=='c'&&s[i+1]==':'&&s[i+2]=='='&&s[i+4]==';') { if(s[i+3]<='9'&&s[i+3]>='0') { c=(int)(s[i+3]-'0'); } if((s[i+3])=='a') { c=a; } if((s[i+3])=='b') { c=b; } } } cout<<a<<" "<<b<<" "<<c; } ```
by lyyddj @ 2024-08-21 16:42:14


|