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 <stdio.h> #include <stdlib.h> int unsortness(char *arr,int n) { int i, j; int unsortnessCount=0; for (i = 0; i < n; i++) { for (j = i+1; j < n; j++) { if (arr[i] > arr[j]) { unsortnessCount++; } } } return unsortnessCount; } int main() { int n, m; int i,j; int temp; char* arry[50]; int *unsort1; int *unsort2; scanf("%d %d", &n, &m); for (i = 0; i < m; i++) { arry[i] = (char*)malloc(sizeof(char)*n); scanf("%s",arry[i]); } unsort1 = (int*)calloc(m,sizeof(int));//存放unsort值 unsort2 = (int*)calloc(m, sizeof(int));//存放unsort值 for (i = 0; i < m; i++) { unsort1[i]=unsortness(arry[i],n); unsort2[i] = unsort1[i]; } for (i = 0; i < m; i++) { for (j= i+1; j < m; j++) { if (unsort1[i] > unsort1[j]) { temp=unsort1[i] ; unsort1[i] = unsort1[j]; unsort1[j] = temp; } } } for (i = 0; i < m; i++) { for (j = 0; j < m; j++) { if (unsort1[i] == unsort2[j]) printf("%s\n",arry[j]); } } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator