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呢#include <stdio.h> #include <stdlib.h> #include <string.h> typedef struct { char name[30]; int weight; }List; void insertion_sort(List dieter[], int n); int main() { List dieter[10]; char ctrl[100]; int days, start_w; char * tokseps = " "; char * p; int i, j; int flag; flag = 0; freopen("D:\\in.txt", "r", stdin); while(gets(ctrl) && strcmp(ctrl, "START") == 0) { if(flag) printf("\n"); else flag = 1; for(i = 0; gets(ctrl) && strcmp(ctrl, "END") != 0; i++) { p = strtok(ctrl, tokseps); strcpy(dieter[i].name, p); p = strtok(NULL, tokseps); days = atoi(p); p = strtok(NULL, tokseps); start_w = atoi(p); if(start_w - days >= 1) dieter[i].weight = start_w - days; else dieter[i].weight = 1; } insertion_sort(dieter, i); for(j = 0; j < i; j++) printf("%s\n", dieter[j].name); } return 0; } void insertion_sort(List dieter[], int n) { int i, j; List temp; for(i = 1; i < n; i++) { temp = dieter[i]; for(j = i - 1; j >= 0 && dieter[j].weight < temp.weight; j--) dieter[j + 1] = dieter[j]; dieter[j + 1] = temp; } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator