| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
新手参考,大神勿进题意:遍历字符串中相隔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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator