http://poj.org/problem?id=3096
for循环真是奇妙!
#include <string.h>
#include <stdio.h>
#include <string>
#include <map>
using namespace std; int main()
{
char a[],st[];
int l,flag;
while(scanf("%s",a)!=EOF)
{
if(a[]=='*') break;
l=strlen(a);
if(l<=)
{
printf("%s is surprising.\n",a);
continue;
}
flag=;
for(int i=;i<=l-;i++)
{
map<string,int>q;//相当于定义了局部变量,每次执行for循环相当与重新赋值或者q.clear();
for(int j=;j<=l--i;j++)
{
st[]=a[j];
st[]=a[j++i];//i代表间隔
st[]='\0';
q[st]++;
if(q[st]>=)
{
flag=;
break;
}
}
if(flag==)
{
printf("%s is NOT surprising.\n",a);
break;
} }
if(flag==) printf("%s is surprising.\n",a);
}
return ;
}