poj 3096 Surprising Strings

本文介绍了一个判断字符串是否具有“惊喜特性”的算法实现。通过两两比较字符串中所有可能的字符组合来确定其是否满足条件:任意两个不相邻的字符组成的字符串在遍历过程中不能重复出现。若满足条件,则认为该字符串是惊喜的。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

很简单的题了吧……

/*
 * Author: stormdpzh
 * POJ: 3096 Surprising Strings
 * Time: 2012/5/7 21:28:34
 */
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <algorithm>
#include <functional>

#define sz(v) ((int)(v).size())
#define rep(i, n) for(int i = 0; i < n; i++)
#define repf(i, a, b) for(int i = a; i <= b; i++)
#define out(n) printf("%d\n", n)
#define wh(n) while(scanf("%d", &n) != EOF)
#define whz(n) while(scanf("%d", &n) != EOF && n != 0)
#define lint long long

using namespace std;

set<string> st;
string str;

int main()
{
    //freopen("data.in", "r", stdin);
    while(cin >> str && str != "*") {
        bool flag = true;
        int len = str.size();
        for(int i = 0; i < len - 1; i++) {
            st.clear();
            for(int j = 0; j < len - i - 1; j++) {
                string tmp = "";
                tmp += str[j];
                tmp += str[j + 1 + i];
                if(st.find(tmp) == st.end()) {
                    st.insert(tmp);
                }
                else {
                    flag = false;
                    break;
                }
            }
            if(!flag) break;
        }
        if(flag)
            cout << str << " is surprising." << endl;
        else
            cout << str << " is NOT surprising." << endl;
    }
    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值