Uva--644 (字符串处理)

2014-05-31 21:42:46

题意 & 思路:小数据匹配前缀,直接strncmp()函数写之,1编A,(如果每条数据长而数据量大,考虑KMP)

#include <cstdio>
#include <iostream>
#include <string.h>
using namespace std;

int main(){
    int cnt = 0,num = 1;
    char code[8][11];
    memset(code,0,sizeof(code));
    while(scanf("%s",code[cnt]) == 1){
        if(code[cnt][0] == '9'){
            int flag = 1;
            for(int i = 0; flag && i < cnt; i++){
                for(int j = 0; j != i && j < cnt; j++){
                    if(strncmp(code[i],code[j],strlen(code[i])) == 0
                            || strncmp(code[i],code[j],strlen(code[j])) == 0){
                        flag = 0;
                        break;
                    }
                }
            }
            printf("Set %d ",num++);
            if(flag)    printf("is immediately decodable\n");
            else        printf("is not immediately decodable\n");
            //init
            cnt = 0;
            continue;
        }
        ++cnt;
    }
    return 0;
}

 

posted @ 2014-05-31 21:44  Naturain  阅读(98)  评论(0编辑  收藏  举报