Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为什么WA,哪位高手帮帮忙#include<stdio.h> #include<string.h> int main(void) { char price[30]; int len; int i; int j; int t; int flag; int sum; while(scanf("%s",&price)!=EOF) { len=strlen(price); flag=0; sum=0; for(i=0;i<len;i++) { if(price[i]=='.')sum++; } if((price[0]=='0'&&price[1]!='.')||price[len-1]=='.')printf("Input error\n"); else if(sum>1)printf("Input error\n"); else { for(i=len-1;i>0;i--) { if(price[i]=='6') { flag=1; price[i]='9'; break; } else if(price[i]=='2') { flag=1; price[i]='5'; break; } else { for(j=i-1;j>0;j--) { if(price[j]=='.') { j--; if(price[i]>price[j]) { flag=1; t=price[i]; price[i]=price[j]; price[j]=t; } break; } if(price[i]>price[j]) { flag=1; t=price[i]; price[i]=price[j]; price[j]=t; break; } } } } if(flag==0) printf("The price cannot be raised.\n"); if(flag==1) printf("%s\n",price); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator