uva 644 Immediate Decodability

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <map>
#include <vector>
#include <set>
using namespace std;
#define N 1000000
char a[N][201];
int cnt, step;
int main()
{
    cnt = 0; step = 0;
    int flag = 0;
    char tmp[201];
    while(~scanf("%s", tmp))
    {
        if(tmp[0]=='9')
        {
            step++;
            cnt=0;
            if(flag)
                printf("Set %d is not immediately decodable\n", step);
            else
                printf("Set %d is immediately decodable\n", step);
            flag = 0;
            continue;
        }
        if(flag)
            continue;
        for(int i = 0; i < cnt; i++)
        {
            int len = min(strlen(tmp), strlen(a[i]));
            int j;
            for(j = 0; j < len; j++)
                if(tmp[j] != a[i][j])
                    break;
            if(j==len)
                {flag = 1;break;}
        }
        if(!flag)
            strcpy(a[cnt++], tmp);
    }

    return 0;
}




你可能感兴趣的:(uva 644 Immediate Decodability)