hdu 统计难题(map)
生活随笔
收集整理的這篇文章主要介紹了
hdu 统计难题(map)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1251
?
map的強大之處,但是運行時間太長。
?
代碼:
1 #include <stdio.h> 2 #include <string.h> 3 #include <math.h> 4 #include <algorithm> 5 #include <iostream> 6 #include <ctype.h> 7 #include <iomanip> 8 #include <queue> 9 #include <map> 10 #include <stdlib.h> 11 using namespace std; 12 13 map<string,int> M; 14 15 int main(){ 16 string x; 17 char a; 18 while(true){ 19 scanf("%c",&a); 20 if(a=='\n'){ 21 scanf("%c",&a); 22 x=""; //字符串 x 清空 23 } 24 if(a=='\n')break; 25 x+=a; 26 M[x]+=1; 27 } 28 while(cin>>x) 29 printf("%d\n",M[x]); 30 return 0; 31 }?
轉載于:https://www.cnblogs.com/wangmengmeng/p/4875789.html
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的hdu 统计难题(map)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用JS的正则表达式如何判断输入框内为中文
- 下一篇: Android之PowerManager