• POJ 3096:Surprising Strings


    Surprising Strings
    Time Limit: 1000MS   Memory Limit: 65536K
    Total Submissions: 6258   Accepted: 4072

    Description

    The D-pairs of a string of letters are the ordered pairs of letters that are distance D from each other. A string is D-unique if all of its D-pairs are different. A string is surprising if it is D-unique for every possible distance D.

    Consider the string ZGBG. Its 0-pairs are ZG, GB, and BG. Since these three pairs are all different, ZGBG is 0-unique. Similarly, the 1-pairs of ZGBG are ZB and GG, and since these two pairs are different, ZGBG is 1-unique. Finally, the only 2-pair of ZGBG is ZG, so ZGBG is 2-unique. Thus ZGBG is surprising. (Note that the fact that ZG is both a 0-pair and a 2-pair of ZGBG is irrelevant, because 0 and 2 are different distances.)

    Acknowledgement: This problem is inspired by the "Puzzling Adventures" column in the December 2003 issue of Scientific American.

    Input

    The input consists of one or more nonempty strings of at most 79 uppercase letters, each string on a line by itself, followed by a line containing only an asterisk that signals the end of the input.

    Output

    For each string of letters, output whether or not it is surprising using the exact output format shown below.

    Sample Input

    ZGBG
    X
    EE
    AAB
    AABA
    AABB
    BCBABCC
    *

    Sample Output

    ZGBG is surprising.
    X is surprising.
    EE is surprising.
    AAB is surprising.
    AABA is surprising.
    AABB is NOT surprising.
    BCBABCC is NOT surprising.

    大水题,判断一个字符串中的两个字符组是否相等,一开始是连着的两个字符组,然后看隔一个,隔两个。。。

    题目分类上说是考察STL的用法。

    代码:

    #include <iostream>
    #include <algorithm>
    #include <cmath>
    #include <vector>
    #include <string>
    #include <cstring>
    using namespace std;
    
    vector <string> zifu;
    
    bool pend()
    {
    	int m = zifu.size();
    	int i,j;
    
    	for(i=0;i<m;i++)
    	{
    		for(j=i+1;j<m;j++)
    		{
    			if(zifu[i]==zifu[j])
    				return false;
    		}
    	}
    	return true;
    }
    
    int main()
    {
    	string a;
    	int len,i,k;
    	while(cin>>a)
    	{
    		if(a=="*")
    			break;
    		len=a.length();
    
    		int flag=1;
    		for(k=1;k<len;k++)
    		{
    			for(i=0;i+k<len;i=i++)
    			{
    				string temp="";
    				temp += a[i];
    				temp += a[i+k];
    				zifu.push_back(temp);
    			}
    			if(!pend())
    			{
    				cout<<a<<" is NOT surprising."<<endl;
    				flag=0;
    				break;
    			}
    			else
    			{
    				zifu.clear();
    			}
    		}
    		if(flag)
    			cout<<a<<" is surprising."<<endl;
    		zifu.clear();
    	}
    
    	return 0;
    }
    



    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    MySQL 基本字段类型
    《将博客搬至CSDN》
    【转载·收藏】 html5手机网站自适应需要加的meta标签
    SQL LIKE操作符 Thinkphp
    Thinkphp判断值是否为空
    Thinkphp重复字段过滤
    Thinkphp框架删除确认对话框
    PHP微信公众平台开发高级篇——群发接口(慕课网学习笔记)
    通过当前cateid来判断切换tab
    js获取当前页面的url中id
  • 原文地址:https://www.cnblogs.com/lightspeedsmallson/p/4785838.html
Copyright © 2020-2023  润新知