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

一开始把题目意思理解错了,后来发现其实相当简单的一道题,一次就AC了

Posted by 201501060326 at 2016-04-01 17:15:33 on Problem 1016
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;
int array[10];
char tt[100];
struct strings
{
    char s[100];
};
int judge(char ss[],struct strings str[],int count)
{
    int i,j;
    for(i=0; ss[i]!=0; i++)
    {
        if(ss[i]=='0') array[0]++;
        else if(ss[i]=='1') array[1]++;
        else if(ss[i]=='2') array[2]++;
        else if(ss[i]=='3') array[3]++;
        else if(ss[i]=='4') array[4]++;
        else if(ss[i]=='5') array[5]++;
        else if(ss[i]=='6') array[6]++;
        else if(ss[i]=='7') array[7]++;
        else if(ss[i]=='8') array[8]++;
        else if(ss[i]=='9') array[9]++;
    }
    for(i=0,j=0; i<=9; i++)
    {
        if(array[i]>=10)
        {
            tt[j]=array[i]/10+'0';
            tt[j+1]=array[i]%10+'0';
            tt[j+2]=i+'0';
            j=j+3;
        }
        else if(array[i]>0)
        {
            tt[j]=array[i]+'0';
            tt[j+1]=i+'0';
            j=j+2;
        }
        array[i]=0;
    }
    if(strcmp(tt,ss)==0) return 0;
    for(i=1; i<count; i++)
    {
        if(strcmp(tt,str[i].s)==0)
            return i;
    }
    memset(ss,0,sizeof(ss));
    strcpy(ss,tt);
    memset(tt,0,sizeof(tt));
    return -1;
}
int main()
{
    struct strings str[20];
    char ss[100];
    bool flag;
    int i,j,count,step_1,step_2;
    while(cin>>ss)
    {
        count=0;
        step_2=1;
        flag=false;
        if(strcmp(ss,"-1")==0) break;
        strcpy(str[count++].s,ss);
        while(step_2<=15)
        {
            step_1=judge(ss,str,count);
            if(step_1==0)
            {
                for(i=0; str[0].s[i]!=0; i++)
                    cout<<str[0].s[i];
                cout<<" is self-inventorying";
                if(step_2>1)
                    cout<<" after "<<step_2-step_1-1<<" steps";
                cout<<endl;
                flag=true;
                break;
            }
            else if(step_1>=1)
            {
                for(i=0; str[0].s[i]!=0; i++)
                    cout<<str[0].s[i];
                cout<<" enters an inventory loop of length "<<step_2-step_1<<endl;
                flag=true;
                break;
            }
            else
                strcpy(str[count++].s,ss);
            step_2++;
        }
        if(!flag)
        {
            for(i=0; str[0].s[i]!=0; i++)
                cout<<str[0].s[i];
            cout<<" can not be classified after 15 iterations"<<endl;
        }
        for(i=0; i<count; i++)
            memset(str[i].s,0,sizeof(str[i].s));
        memset(ss,0,sizeof(ss));
        memset(tt,0,sizeof(tt));
    }
    return 0;
}

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