zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    继承 多态
    封装练习
    PHP 面向对象封装
    面向对象 类和对象
    PHP前端和数据库的连接
    数组2
    PHP数组
    正则表达式
    PHP字符串
    linux基础
  • 原文地址:https://www.cnblogs.com/zhuiyicc/p/9477039.html
Copyright © 2011-2022 走看看