STL水题。map+string的应用
提供两种思路:
1)用map标记字符串是否出现过,利用map检查是否有重复。
2)用hash数组,以两个字符的ASCII码组成一个四位数作为key,比较是否有重复。
下面是map+string代码:172K+16MS
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <string>
#include <map>
#define Max 80
using namespace std;
char Input[Max];
char help[3];
bool Is_right(){
int len=strlen(Input);
for(int i=len-2;i>=0;i--){
map<string,bool> cap;
for(int j=0;j<=len-i-2;j++){
string temp;
//help[0]=Input[j],help[1]=Input[j+i+1],help[2]='\0';
//temp.assign(help);
temp.push_back(Input[j]);
temp.push_back(Input[j+i+1]);
if(cap[temp])
return false;
cap[temp]=true;
}
}
return true;
}
int main(){
while(scanf("%s",Input),strcmp(Input,"*")!=0){
getchar();
if(Is_right())
printf("%s is surprising.\n",Input);
else
printf("%s is NOT surprising.\n",Input);
}
return 0;
}