zoukankan      html  css  js  c++  java
  • HDOJ 2736 Surprising Strings

    Surprising Strings

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
    Total Submission(s): 294    Accepted Submission(s): 209

    Problem 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.
     

    自己写的代码一直wa....求高手

    #include <iostream>
    #include <string>
    #include <string.h>
    #include <cctype>
    using namespace std;
    ///**wa代码**/
    bool judge(string a,string b)
    {
        for(int i=0; i<a.length(); i++)
        {
            for(int j=i+1; j<a.length(); j++)
            {
                if(a[i]==a[j] && b[i]==b[j])
                {
                    return true;
                }
            }
        }
        return false;
    }
    int main()
    {
        string s="";
        while(cin>>s && s[0] != '*')
        {
            string str,ans1,ans2,table1,table2,count1,count2;
            str=ans1=ans2=table1=table2=count1=count2="";
            int k=0;
            str=s;
            for(int i=0; i<s.length(); i++)
            {
                if(islower(s[i]))
                    s[i]=toupper(s[i]);
                else
                    s[i]=s[i];
            }
            // cout<<s<<" "<<str<<endl;
            if(s.length()>1)
            {
                for(int i=0; i<s.length()-1; i++)
                {
                    ans1+=s[i];
                    ans2+=s[i+1];
                }
            }
            if(s.length()>2)
            {
                for(int i=0; i<s.length()-2; i++)
                {
                    table1+=s[i];
                    table2+=s[i+2];
                }
            }
            if(s.length()>3)
            {
                for(int i=0; i<s.length()-3; i++)
                {
                    count1+=s[i];
                    count2+=s[i+3];
                }
            }
    
            if(!judge(ans1,ans2) && !judge(table1,table2) &&!judge(count1,count2))
                cout<<str<<" is surprising."<<endl;
            else
                cout<<str<<" is NOT surprising."<<endl;
            /*cout<<ans1<<" ";
            cout<<ans2<<" ";
            cout<<table1<<" ";
            cout<<table2<<" "<<count1<<" "<<count2<<endl;*/
        }
    }
    
    
    
    
    /**别人正确代码**/
    #include<iostream>
    #include<string>
    using namespace std;
    int map[26][26];
    char str[10000];
    int change(char a)
    {
        return (int)(a-'A');
    }
    int main()
    {
        int i,j;
        while(cin>>str&&str[0]!='*')
        {
            int len=strlen(str);
            int flag=0;
            for(i=0; i<=len-2; i++)
            {
                memset(map,0,sizeof(map));
                for(j=0; j<=len-2-i; j++)
                {
                    int x=change(str[j]);
                    int y=change(str[j+i+1]);
                    if(map[x][y])
                    {
                        flag=1;
                        break;
                    }
                    else map[x][y]=1;
                }
                if(flag==1) break;
            }
            if(flag) cout<<str<<" is NOT surprising."<<endl;
            else cout<<str<<" is surprising."<<endl;
    
        }
        return 0;
    }
    


  • 相关阅读:
    北京西格玛大厦微软社区精英 Visual Studio 2010 技术交流会记录
    2010522 Windows Phone 开发者日
    SharePoint Server 2010 RTM 安装过程(图)
    Windows HPC Server 2008 R2 简体中文版 下载
    转:Community Clips 使用指南
    关于CS0016: Could not write to output file ‘c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files… ‘Access is denied.’ 的解决办法
    岗位职责
    PowerPoint 2010 的广播幻灯片功能尝试了一下,可以用。
    Silverlight 4 五
    Windows Server AppFabric 简体中文 下载地址
  • 原文地址:https://www.cnblogs.com/riskyer/p/3303820.html
Copyright © 2011-2022 走看看