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 |
问题在这In Reply To:G++ is AC,C++ is WA , but why? Posted by:xax10000 at 2006-04-03 11:29:32 > #include<iostream> > #include<cstdio> > #include<string> > #include<iomanip> > #include<cmath> > using namespace std; > int main(int argc, char* argv[]) > { > char a[40], b[40]; ---------------------------------- > int n; > cin>>n; > cin.ignore(); > for(int j = 1; j <= n; ++ j){ > gets(a); > gets(b); > int num1[26] = {0}, num2[26] = {0}; > int len1 = strlen(a); > int len2 = strlen(b); > int i, sum = 0; > for(i = 0; i < len1; ++ i) num1[ a[i] - 'a'] ++; > for(i = 0; i < len2; ++ i) num2[ b[i] - 'a'] ++; > for(i = 0; i < 26; ++ i) sum += (int)abs(num1[i] - num2[i]); > cout<<"Case #"<<j<<": "<<sum<<endl; > } > return 0; > } 数组开少了 这是我改完后的程序 #include<iostream> #include<cstdio> #include<cmath> using namespace std; int main() { char a[200],b[200]; int n,i,j,sum,num2[26],num1[26]; scanf("%d",&n);scanf("\n"); for(j=1;j<=n;j++) { gets(a); gets(b); memset(num1,0,sizeof(num1)); memset(num2,0,sizeof(num2)); sum=0; for(i=0;i<strlen(a);i++) num1[a[i]-'a']++; for(i=0;i<strlen(b);i++) num2[b[i]-'a']++; for(i=0;i<26;i++) sum+=(int)abs(num1[i]-num2[i]); printf("Case #%d: %d\n",j,sum); } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator