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;
} 

 

上一篇:杭电1016 素数环+DFS基础变形


下一篇:redis主从复制以及SSDB主主复制环境部署记录(四)