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 |
帮我看一下程序为什么总是Runtime Error#include <string.h> #include <iostream> using namespace std; #define MaxLines 100 #define MaxLen 50 int main() { char strings[MaxLines][MaxLen]; char *temp; char ch; int *order; int n;//the length of the strings int m;//the number of the strings int i; int j; int k; int sum = 0; cin >>n>>m; order = new int[m]; temp = new char[n]; for (i = 0;i < m;i++) cin >>strings[i]; for (i = 0;i < m;i++) { for (j = 0;j < n;j++) { ch = strings[i][j]; for (k = j;k < n;k++) { if (ch > strings[i][k]) sum = sum + 1; } } order[i] = sum; sum = 0; } for (i=0;i<m;i++) { for (j=i;j<m;j++) { if (order[i] > order[j]) { strcpy(temp,strings[i]); strcpy(strings[i],strings[j]); strcpy(strings[j],temp); k = order[j]; order[j] = order[i]; order[i] = k; } if (order[i] == order[j]) continue; } } for (i = 0;i < m;i++) cout <<strings[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