0分是真的难受 WA RE

P1553 数字反转(升级版)

我很多例题包括有的大佬在讨论区发的例题都过了 可就是不过 求助
by 律途 @ 2019-01-23 10:18:44


dalao,蒟蒻有个解法,不知当讲不当讲
by MuYC @ 2019-01-23 10:23:37


```cpp #include <bits/stdc++.h> char a[200000],b[2000000]; using namespace std; int main(){ int i,j,k,n,bai,len,m,p=0,p1=0,con; cin>>a; len=strlen(a)-1; for(i=0;i<=len;i++){ if(a[i]=='.'||a[i]=='/'){ k=0; if(a[i]=='.') p=i; else p1=i; for(j=i+1;j<=len;j++){ b[k]=a[j]; a[j]='\0'; k++; } a[i]='\0'; break; } } if(a[strlen(a)-1]=='%'){bai=1;a[strlen(a)-1]=='\0';} reverse(a,a+strlen(a)); reverse(b,b+strlen(b)); if(bai==1){ con=1; for(i=1;i<strlen(a);i++){ if(a[i]!='0')con=0; if(con!=1)cout<<a[i]; } cout<<"%"; } else if(p1!=0){ con=1; for(i=0;i<strlen(a);i++){ if(a[i]!='0')con=0; if(con!=1)cout<<a[i]; } con=1; cout<<"/"; for(i=0;i<k;i++){ if(b[i]!='0')con=0; if(con!=1)cout<<b[i]; } } else if(p1==0&&p==0&&bai!=1){ con=1; for(i=0;i<strlen(a);i++){ if(a[i]!='0')con=0; if(con!=1)cout<<a[i]; } } else if(p!=0){ con=1; for(i=0;i<strlen(a);i++){ if(a[i]!='0')con=0; if(con!=1)cout<<a[i]; } con=1; cout<<"."; for(i=k-1;i>=0;i--) if(b[i]!='0'){con=i;break;} for(i=0;i<=con;i++) cout<<b[i]; } return 0; } ``` AC代码
by MuYC @ 2019-01-23 10:24:17


哎呀呀,发错代码了
by MuYC @ 2019-01-23 10:25:55


这是70分代码
by MuYC @ 2019-01-23 10:26:09


满分 ```cpp #include <bits/stdc++.h> char ch[300000],a[300000],b[300000],c; using namespace std; int main(){ int flag=1,k=-1,i; cin>>ch; for(int i = 0;i < strlen(ch);i++){ if(ch[i]>='0'&&ch[i]<='9'){ if(flag==2)k++,b[k]=ch[i]; if(flag==1)a[i]=ch[i]; } else flag++,c=ch[i]; } reverse(a,a+strlen(a)); flag=1; for(i = 0;i < strlen(a);i++){ if(flag==1&&a[i]=='0')continue; if(a[i]!='0')flag=0; cout<<a[i]; } if(flag==1) cout<<0; putchar(c); reverse(b,b+strlen(b)); if(c=='.'){ int j = strlen(b)-1; while(j>=1&&b[j]=='0')b[j]='\0',j--; } if(strlen(b)!=1){ int j=0; while(b[j]=='0')j++; for(i=j;i<strlen(b);i++) cout<<b[i]; } else cout<<b; return 0; } ```
by MuYC @ 2019-01-23 10:53:50


@[Mr_杨t_t](/space/show?uid=67817) 我是只会c的萌新 虽然看不懂但是谢谢大佬
by 律途 @ 2019-01-23 11:46:29


@[Mr_杨t_t](/space/show?uid=67817) 解决了 可能是我的前面的while语句中有问题 改成用scanf输入就过了 谢谢dalao
by 律途 @ 2019-01-23 12:07:24


|