poj 3096 Surprising Strings
来源:互联网 发布:c语言是否窗口 编辑:程序博客网 时间:2024/06/06 19:31
题意:
看题目示例领会
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.
解题思路:
用map存每个pair,判断是否存在即可。
代码:
#include <iostream>#include <cstdio>#include <map>#include <string>#include <cstring>using namespace std;int main(){ string str; while(cin>>str) { map<string, int>d[80]; if(str=="*")break; int i, j; int len=str.size(); string mpstr; int ans=1; for(i=1; i<=len-1; i++) { for(j=0; j+i<len; j++) { char e[11]; e[0]=str[j]; e[1]=str[j+i]; e[2]='\0'; mpstr=e;// cout<<mpstr<<endl; if(d[i].find(mpstr)!=d[i].end())ans=0; else d[i][mpstr]=1; } } if(ans) { cout<<str<<" is surprising."<<endl; } else cout<<str<<" is NOT surprising."<<endl; } return 0;}
0 0
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- POJ 3096 Surprising Strings
- POJ 3096 Surprising Strings
- POJ 3096 Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- POJ 3096:Surprising Strings
- Surprising Strings(POJ -3096
- poj 3096 Surprising Strings
- poj-3096-Surprising Strings
- poj 3096 Surprising Strings
- poj 3096 Surprising Strings
- POJ 3096 Surprising Strings
- poj 3096 Surprising Strings
- js删除最后一个字符
- HTTPS的工作原理
- OpenGL核心技术之模版测试
- Android 热更新 Bugly(Tinker)接入
- springmvc工程文件上传下载
- poj 3096 Surprising Strings
- nginx隐藏版本信息
- 文件格式转换小工具
- C++ STL标准入门汇总
- System.Web.HttpContext.Current.Cache与System.Web.HttpRuntime.Cache指向同一个引用
- 新签名文件配置方式
- 特征的转换_05-标签索引的转换与特征的组合
- jquery 设置浏览器屏蔽键盘回退功能
- iOS子线程更新UI的两种方法