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,(C++),thx~#include<iostream> #include<cstring> #include<cmath> using namespace std; int f(char a[51],int len) { int sum=0; for(int i=1;i<=len-1;i++) { for(int j=i+1;j<=len;j++) { if(a[i]>a[j]) sum++; } } return sum; } int main() { int num,len,m,i,j; char a[101][51]; cin>>len>>num; for(i=1;i<=num;i++) { for(j=1;j<=len;j++) { cin>>a[i][j]; } } int p; p=f(a[1],len); for(i=1;i<=num;i++) { if(p<=f(a[i],len)) p=f(a[i],len); } for(m=1;m<=p;m++) { for(i=1;i<=num;i++) { if(f(a[i],len)==m) { for(j=1;j<=len;j++) { cout<<a[i][j]; } cout<<endl; } } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator