Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

为什么WA呢

Posted by zhangzhiwei at 2009-03-22 20:53:12 on Problem 2218
#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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator