我試過把“g”放數字前面,可以印出來,但是g放在數字後面就印不出來,請問高手們能幫我看看嗎?
#include <iostream>
using namespace std;
int main()
{
int a,b,c,x,y,z,w,n,m,i,j;
string s;
cin >>a;
for(i=0;i<a;i++){
cin>>x>>y>>z>>w>>n>>m;
b=0;
cin.ignore();
getline(cin,s,'\n');
c=s.size();
if (c==0){cout<<m;}
else{
for(j=0;j<c;j++){
if(s[j]=='1'){
if(m-b<=0){m=m-b;j=c;}
else{m=m+x-b;j=j+1;}}
else if(s[j]=='2'){
if(m-b<=0){m=m-b;j=c;}
else{m=m+y-b;j=j+1;
if(m<=0){j=c;}}}
else if(s[j]=='3'){
if(m-b<=0){m=m-b;j=c;}
else{m=m-z-b;j=j+1;
if(m<=0){j=c;}}}
else if(s[j]=='4'){
if(m-b<=0){m=m-b;j=c;}
else{m=m-w-b;b=b+n;j=j+1;
if(m<=0){j=c;}}}
else if(s[j]=='0'){
if(m-b<=0){m=m-b;j=c;}
else{m=m-b;j=j+1;
if(m<=0){j=c;}}}}
if(m<=0){cout<<"bye~Rabbit"<<endl;}
else{cout<< m << 'g' <<endl; }
}}
return 0;}
====================================
您的答案為: 20627bye~Ra ...略
正確答案為: 20627g