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 |
郁闷死人了!!#include <iostream> #include <string> #include <math.h> using namespace std; string sa,sb; int go(){ int i; for(i=0;sa[i]!='?';i++){ if( sb[i]>sa[i]) return -10000; if(sb[i]<sa[i]) {sa=sb;return 10;} } sa[i]=sb[i]; return 9-(sb[i]-'0'); } long long pow(long long a,long long b){ int i; long long t=1; for(i=1;i<=b;i++){ t*=a; } return t; } int main(){ long long i,j,n,m; while(cin >> sa && sa!="#"){ cin >> sb; n=0; long long sum=0; for(i=0;i<sa.size();i++) if(sa[i]=='?') n++; bool f=false; for(i=1;i<n;i++){ m=go(); if(m==-10000) {f=true;break;} if(m==10){f=true;sum+=m*pow(10,n-i);break;} sum+=m*pow(10,n-i); } if(!f){ for(i=0;i<sa.size() && sa[i]!='?';i++); for(sa[i]='0';sa[i]<='9';sa[i]++){ if(sa>sb) sum++; } } cout << sum << endl; } } 上面的AC 下面的WA #include <iostream> #include <string> #include <math.h> using namespace std; string sa,sb; int go(){ int i; for(i=0;sa[i]!='?';i++){ if( sb[i]>sa[i]) return -10000; if(sb[i]<sa[i]) {sa=sb;return 10;} } sa[i]=sb[i]; return 9-(sb[i]-'0'); } /*long long pow(long long a,long long b){ int i; long long t=1; for(i=1;i<=b;i++){ t*=a; } return t; }*/ int main(){ long long i,j,n,m; while(cin >> sa && sa!="#"){ cin >> sb; n=0; long long sum=0; for(i=0;i<sa.size();i++) if(sa[i]=='?') n++; bool f=false; for(i=1;i<n;i++){ m=go(); if(m==-10000) {f=true;break;} if(m==10){f=true;sum+=m*pow(10,n-i);break;} sum+=m*pow(10,n-i); } if(!f){ for(i=0;i<sa.size() && sa[i]!='?';i++); for(sa[i]='0';sa[i]<='9';sa[i]++){ if(sa>sb) sum++; } } cout << sum << endl; } } 为什么double转long long 会出错? Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator