Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

2个for循环搞定,附拙劣代码

Posted by makuiyu at 2014-01-15 13:06:25 on Problem 3096
#define N 700
#define M 80

using namespace std;

int d[N];
char s[M];

int change(char c1, char c2)
{
    return (c1-'A')*26 + (c2-'A');
}

bool judge()
{
    int l = strlen(s);
    for(int i=1; i<l-1; ++i)
    {
        memset(d, 0, sizeof(d));
        for(int j=0; i+j<l; ++j)
        {
            int k = change(s[j], s[j+i]);
            if(d[k] != 0)
                return false;
            else
                d[k] = 1;
        }
    }
    return true;
}

int main()
{
    while(scanf("%s", s)!=EOF && s[0]!='*')
        printf("%s is %s.\n", s, judge()?"surprising":"NOT surprising");
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator