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;
}
}
相關文章
- 深度學習和圖形學渲染的結合和應用深度學習
- 新媒體光影秀和紅色文化的結合應用
- pairAI
- Set和Map資料結構。資料結構
- Lua中pair和ipair的區別AI
- KGB知識圖譜技術提升和產業應用緊密結合產業
- workerman結合laravel開發線上聊天應用Laravel
- D - Square PairAI
- [LeetCode] 3096. Minimum Levels to Gain More PointsLeetCodeAI
- 演算法思維體操:用JavaScript和Python自己實現reduceRight和map(連結串列)演算法JavaScriptPython
- 結合 Shell 對 Koa 應用執行環境檢查
- 【JUC】4-FutrueTask結合執行緒池的應用執行緒
- ChatGPT調研分析與應用場域結合構想ChatGPT
- BFS和Dijkstra結合
- 【POJ 2249】 Binomial Showdown 組合數學 排列組合計算
- ES6之Set和Map資料結構資料結構
- 複合材料在前述行業的輕量化結構應用行業
- 淺談 CBDC 系統與區塊鏈的結合應用區塊鏈
- 用 React 結合 SAP UI5 Web Components 來開發 SAP Fiori 應用ReactUIWeb
- Set 和Map
- map和multimap
- [NOIP2008 提高組] 笨小猴——map的應用
- STL:map用法總結
- apply,map,applymap總結APP
- Map 資料結構資料結構
- JSONObject應用Json字串和Object物件之間的轉換,Map封裝資料思路JSONObject字串物件封裝
- 用pprof分析map和slice的記憶體呼叫記憶體
- 企業商品產品結合區塊鏈技術應用方案區塊鏈
- c++ map和unordered_map比較C++
- go map 和 sliceGo
- python map和lambdaPython
- FMEA和HAZOP在煤氣櫃風險分析綜合應用
- Java 組合模式及其應用Java模式
- LlamaIndex RAG 和ReAct結合使用AIIndexReact
- `GitHub page` 和 `gitbook` 結合使用Github
- intervention/image和oss結合使用
- nodejs應用連結NodeJS
- [翻譯]map和reduce,處理資料結構的利器資料結構
- match函式簡單介紹以及與index函式結合應用函式Index