pair 和 map結合應用——POJ 3096
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]++;
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 6613 | Accepted: 4302 |
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
ZGBG X EE AAB AABA AABB BCBABCC *
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;
}
}
相關文章
- 深度學習和圖形學渲染的結合和應用深度學習
- POJ 2503-Babelfish(STL-map)Babel
- 新媒體光影秀和紅色文化的結合應用
- 企業自主創新應結合ERP應用和管理創新(轉)
- pairAI
- Set和Map資料結構。資料結構
- workerman結合laravel開發線上聊天應用Laravel
- 例說資料結構&STL(十三)——pair資料結構AI
- STL::pairAI
- KGB知識圖譜技術提升和產業應用緊密結合產業
- Lua中pair和ipair的區別AI
- struts 應用結合tomcat進行ssl認證Tomcat
- Map總結
- D - Square PairAI
- 增強for迴圈在Map中的應用
- 企業自主創新應結合ERP應用管理創新(轉)
- 結合 Shell 對 Koa 應用執行環境檢查
- ChatGPT調研分析與應用場域結合構想ChatGPT
- 【JUC】4-FutrueTask結合執行緒池的應用執行緒
- nginx應用總結(1)-- 基礎知識和應用配置梳理Nginx
- pat—結構體排序(用map彌補struct缺陷)結構體排序Struct
- Pair_Work ProjectAIProject
- 複合材料在前述行業的輕量化結構應用行業
- 淺談 CBDC 系統與區塊鏈的結合應用區塊鏈
- ucenter與其它應用結合時出現通訊失敗,ucenter應用原理與除錯除錯
- Nginx和Perl的結合Nginx
- Nginx和php的結合NginxPHP
- lucene和NoSQL的結合SQL
- ES6之Set和Map資料結構資料結構
- 用 React 結合 SAP UI5 Web Components 來開發 SAP Fiori 應用ReactUIWeb
- 企業商品產品結合區塊鏈技術應用方案區塊鏈
- 產業結合區塊鏈應用Baas平臺上鍊服務產業區塊鏈
- 業務流程重組與ERP系統應用的結合(轉)
- UVA 11991 STL中map、vector的應用
- Java 組合模式及其應用Java模式
- STL:map用法總結
- Map 資料結構資料結構
- 演算法思維體操:用JavaScript和Python自己實現reduceRight和map(連結串列)演算法JavaScriptPython