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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值