其他分享
首页 > 其他分享> > poj 1016(字符串处理)

poj 1016(字符串处理)

作者:互联网

#include<iostream>
#include<cstring>
using namespace std;
int data[10];
void reverse(char*s,char*t){
    for(int i=0;i<10;i++){
        data[i] = 0;
    }
    for(int i=0;i<strlen(s);i++){
        data[s[i]-'0']++;
    }
    int idx = 0;
    for(int i=0;i<10;i++){
        if(data[i]>0){
            if(data[i]>9){
                t[idx++] = data[i]/10+'0';
                t[idx++] = data[i]%10+'0';
            }
            else{
                t[idx++] = data[i]+'0';
            }
            t[idx++] = i+'0';
        }
    }
    t[idx] = '\0';
}
int main(){
    char s[15][81];
    while(cin>>s[0]){
        if(s[0][0]=='-'&&s[0][1]=='1')break;
        reverse(s[0],s[1]);
        if(strcmp(s[0],s[1])==0){
            cout<<s[0]<<" is self-inventorying "<<endl;
            continue;
        }
        bool flag = true;
        for(int i=2;i<=15;i++){
            reverse(s[i-1],s[i]);
            if(strcmp(s[i-1],s[i])==0){
                cout<<s[0]<<" is self-inventorying after "<<i-1<<" steps"<<endl;
                flag = false;
                break;
            }
            else{
                for(int j=0;j<i;j++){
                    if(strcmp(s[j],s[i])==0){
                        cout<<s[0]<<" enters an inventory loop of length "<<i-j<<endl;
                        flag = false;
                        break;
                    }
                }
                if(flag==false){
                    break;
                }
            }
        }
        if(flag){
            cout<<s[0]<<" can not be classified after 15 iterations"<<endl;
        }
    }
    return 0;
} 

 

标签:10,idx,++,char,int,poj,字符串,1016,data
来源: https://www.cnblogs.com/stevenzrx/p/15057674.html