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 |
Re:帮忙看看啊,VC运行成功了,但就是WA啊!In Reply To:Re:帮忙看看啊,VC运行成功了,但就是WA啊! Posted by:zjazczjazc at 2009-07-23 10:39:18 #include <iostream> #include <string> using namespace std; int main() { int n,m,i,j; char a[100][51] = {0}; int b[55] = {0};//记录每行的逆序数 int count; int flag; int temp; char c[51] = {0}; cin >> n >> m; //直接一一计算各个字符串的逆序数,每串中都依次向后比较各个字母 for(i=0; i<m; i++) { cin >> a[i];//输入一个串 count = 0;//临时变量用来计数 //记录每串的逆序数,若不是由大到小排列则记录下其数目 for(j=0; j<n; j++) { for(int k=j; k<n; k++) { if(a[i][k] < a[i][j]) count ++; } } b[i] = count; } //数字有小到大排序,相应的字符串也相应改变次序(冒泡排序的变形) for(i=1; i < m; i++) { flag = 0; for(j=m-1; j>=i; j--) { if(b[j] < b[j-1]) { //数字交换 temp = b[j-1]; b[j-1] = b[j]; b[j] = temp; //相应的字符串交换 strcpy(c,a[j]); strcpy(a[j],a[j-1]); strcpy(a[j-1],c); flag = 1; } } if(flag == 0) break; } //输出排序后的各个字符串 for(i=0; i<m; i++) { cout << a[i] << 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