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

为何这样能过,这样过不了?

Posted by jhljx at 2014-02-05 22:11:27 on Problem 1493
WA的代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    unsigned int n;
    char a[30][30];
    while(cin>>n)
    {
        if(n==0)
            break;
        int b[15]= {0},min=26,sum=0;
        for(int i=0; i<n; i++)
        {

            for(int j=0; j<25; j++)
            {
                 cin>>a[i][j];

                 if(a[i][j]==' ')

                    b[i]++;
            }
            getchar();
            if(b[i]<=min)
                min=b[i];
        }
        for(int i=0; i<n; i++)
        {
            b[i]-=min;
            sum+=b[i];
        }
        cout<<sum<<endl;
    }
}
AC代码:
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    unsigned int n;
    char a[30];
    while(cin>>n)
    {
        if(n==0)
            break;
        getchar();
        int b[15]= {0},min=26,sum=0;
        for(int i=0; i<n; i++)
        {
            gets(a);
            for(int j=0; j<25; j++)
            {

               if(a[j]==' ')
                    b[i]++;
            }
            if(b[i]<=min)
                min=b[i];
        }
        for(int i=0; i<n; i++)
        {
            b[i]-=min;
            sum+=b[i];
        }
        cout<<sum<<endl;
    }
}

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