pair 和 map结合应用——POJ 3096
来源:互联网 发布:微信点餐系统源码下载 编辑:程序博客网 时间:2024/06/07 15:21
pair用法:
1、定义
pair<第一个参数类型,第二个参数类型>变量名;
eg: pair<char,char>a;
2、赋值
a = make_pair("a","b");
map用法:
1、定义
map<第一个参数类型(键),第二个参数类型(值)>
eg: map<pair<char,char>,int>m;
2、赋值
m[键] = 值;
eg: m[a]++;
Description
The D-pairs of a string of letters are the ordered pairs of letters that are distance D from each other. A string is D-unique if all of its D-pairs are different. A string is surprising if it is D-unique for every possible distance D.
Consider the string ZGBG. Its 0-pairs are ZG, GB, and BG. Since these three pairs are all different, ZGBG is 0-unique. Similarly, the 1-pairs of ZGBG are ZB and GG, and since these two pairs are different, ZGBG is 1-unique. Finally, the only 2-pair of ZGBG is ZG, so ZGBG is 2-unique. Thus ZGBG is surprising. (Note that the fact that ZG is both a 0-pair and a 2-pair of ZGBG is irrelevant, because 0 and 2 are different distances.)
Acknowledgement: This problem is inspired by the "Puzzling Adventures" column in the December 2003 issue of Scientific American.
Input
The input consists of one or more nonempty strings of at most 79 uppercase letters, each string on a line by itself, followed by a line containing only an asterisk that signals the end of the input.
Output
For each string of letters, output whether or not it is surprising using the exact output format shown below.
Sample Input
ZGBGXEEAABAABAAABBBCBABCC*
Sample Output
ZGBG is surprising.X is surprising.EE is surprising.AAB is surprising.AABA is surprising.AABB is NOT surprising.BCBABCC is NOT surprising.
题目解法:
按照间隔距离遍历
{
将map清空
按照字符串长度遍历
{
每种出现过的<键,值>对都放在pair_a中;
记录每种<键,值>对出现自出map[a]++;
}
判断是否有map[a]的值大于等于2
如果有就不是surprising
没有就是 surprising
}
#include<iostream>#include<stdio.h>#include<math.h>#include<string.h>#include<stdlib.h>#include<algorithm>#include<queue>#include<vector>#include<map>using namespace std;char s[105];pair<char,char>a;int flag;map<pair<char,char>,int>m;int main(){ while(scanf("%s",s)!=EOF) { if(s[0]=='*'&&strlen(s)==1)break; int len = strlen(s); int k = 0; for(int j = 1 ; j < len;j++) { m.clear(); for(int i = 0 ; i <len-j;i++) { k++; a = make_pair(s[i],s[i+j]); m[a]++; } flag = 0; for(int i = 0 ; i < len;i++) { a = make_pair(s[i],s[i+j]); if(m[a]>=2) { flag = 1; break; } } if(flag) {cout<<s<<" "<<"is NOT surprising."<<endl;break;} } if(!flag) cout<<s<<" is surprising."<<endl; }}
- pair 和 map结合应用——POJ 3096
- C++:map容器和pair的结合使用
- STL map,vector和pair的混合应用
- C++,map和pair用法
- STL 之 pair 和map
- c++中map和pair
- POJ 2503 ——map应用
- poj 3096(map的应用)
- C++学习笔记——pair与map遍历深究
- STL中的模板类pair 和map
- STL中的模板类pair 和map
- map和pair的配合使用
- 【数据结构】map和pair的配合使用
- set与map和pair容器
- c++ STL 之map 和 pair
- c++中pair和map的区别
- POJ 3297 Open Source STL(map+set+pair)
- hdu 4022 map的一对多实现 map和set的结合应用
- 关于java的一点成长
- iOS 逆向-非越狱手机Hook App
- 从MAVEN迁移到gradle
- xml解析2
- JavaScript给控件添加事件的方法
- pair 和 map结合应用——POJ 3096
- 深度学习FPGA实现基础知识13(向专家致敬--深度学习-LeCun、Bengio和Hinton的联合综述)
- 手机,固话,邮箱,正则表达式验证
- SAS ods output
- notify 容器类的演化
- ES2.x版本的javaAPI使用实例
- View 的绘制流程
- HDU 4772 Zhuge Liang's Password(暴力)
- 基本TCP套接字函数