poj3096

12 篇文章 0 订阅
2 篇文章 0 订阅

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;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值