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

新手参考,大神勿进

Posted by 2004140022 at 2015-12-11 17:53:45 on Problem 3096 and last updated at 2015-12-11 17:55:05
题意:遍历字符串中相隔d的两个字符组成的子串,所有d的相对应的全部子串都不相等,则suprise.
思路:由于并不了解太多子串父串的东西,暴力遍历的。因为只有2个字母,所以双层循环即可。

#include<iostream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<string.h>
#include<algorithm>
#define N 101
using namespace std;
int charge(char *s)
{
    int i,j,len,d;
    len=strlen(s);
    if(len<3)return 1;
    d=1;
    while(d<len)
    {
        for(i=0;i<len-d;i++)
            for(j=i+1;j<len-d;j++)
            if(s[i]==s[j]&&s[i+d]==s[j+d])
                return 0;
        d++;
    }
    return 1;
}
int main()
{
    char s[N];
    while(1)
    {
        scanf("%s",s);
        if(strcmp(s,"*") == 0)break;
        if(charge(s))
            printf("%s is surprising.\n",s);
        else
            printf("%s is NOT surprising.\n",s);
    }
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