poj 3096 Surprising Strings

只需要一个数据结构对字符串进行存储,以及查询是否存在即可。

#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<string>
#include<set>
#include<algorithm>
#include<vector>
#include<queue>
#include<list>
#include<cmath>
#include<cstring>
#include<map>
#include<stack>
using namespace std;
#define INF 0x3f3f3f3f
#define maxn 5005
#define ull unsigned long long
#define ll long long
#define mod 9
set<string> se;
int main(){
    freopen("a.in","r",stdin);
    freopen("b.out","w",stdout);
    string s;
    while(cin >> s && s[0] != '*'){
        int len = s.length();
        bool f = true;
        for(int i = 0;i <= len - 2;++i){
            string str;
            for(int j = 0;j + i + 1 < len;++j){
                str += s[j];
                str += s[j + i + 1];
                if(se.find(str) != se.end()){
                    f = false;
                    break;
                }
                se.insert(str);
                str.clear();
            }
            se.clear();
            if(!f) break;
        }
        if(f) cout << s << " is surprising." << endl;
        else cout << s << " is NOT surprising." << endl;
    }
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/zhuiyicc/p/9477039.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值