poj 3096 Surprising Strings

题目链接:http://poj.org/problem?id=3096

暴力遍历所有字符串,数据比较小,0ms过。

#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;

const int INF=0x3f3f3f3f;
const int maxn=105;
char s[maxn];

bool ok(){
	int len=strlen(s);
	for(int k=1;k<=len-1;k++){
		for(int i=0;i<len-k;i++){
			for(int j=i+1;j<len-k;j++){
				if(s[i]==s[j]&&s[i+k]==s[j+k]){
					return false;
				}
			}
		}
	}
	return true;
}

int main(){
#ifndef ONLINE_JUDGE
    freopen("test.in","r",stdin);
    freopen("test.out","w",stdout);
#endif
    while(~scanf("%s",s)){
    	if(!strcmp(s,"*")) break;
    	int len=strlen(s);
    	if(len<=2){
    		printf("%s is surprising.\n",s);
    		continue;
    	}
    	if(!ok()) printf("%s is NOT surprising.\n",s);
    	else printf("%s is surprising.\n",s);
    }
    return 0;
}


你可能感兴趣的:(poj 3096 Surprising Strings)