zoukankan      html  css  js  c++  java
  • HDU4287-STL模拟水题

    一场2012天津网络预选赛的题,签到题。

    但是还是写了三四十分钟,C++和STL太不熟悉了,总是编译错误不知道怎么解决。

    一开始用的Char [] 后来改成了string,STL和string搭配起来才好用啊。

     1 #include <algorithm>
     2 #include <iostream>
     3 #include <cstring>
     4 #include <ctype.h>
     5 #include <cstdlib>
     6 #include <cstdio>
     7 #include <vector>
     8 #include <string>
     9 #include <queue>
    10 #include <stack>
    11 #include <cmath>
    12 #include <set>
    13 #include <map>
    14 
    15 using namespace std;
    16 
    17 int N,M,T;
    18 map <string ,int> dic; 
    19 string list[5010];
    20 int table[]={2,2,2,3,3,3,4,4,4,5,5,5,6,6,6,7,7,7,7,8,8,8,9,9,9,9};
    21 int main()
    22 {
    23     cin >> T;
    24     string s;
    25     while(T--)
    26     {
    27         cin >> N >> M;
    28         for(int i=0;i<N;i++) {
    29             cin >> list[i];
    30         }
    31         dic.clear();
    32         for(int i=0;i<M;i++)
    33         {
    34             cin >> s;
    35             string num;
    36             for(int k=0;k < (int)s.size();k++)
    37             {
    38                 num += table[s[k]-'a'] + '0';
    39             }
    40             //cout << num << endl;
    41             map<string ,int>::iterator it = dic.find(num);
    42             if(it == dic.end()){
    43                 dic.insert(make_pair(num,1));
    44             }
    45             else
    46                 it->second++;
    47         }
    48         map<string , int>::const_iterator notFound(dic.end());
    49         map<string , int>::const_iterator pos;
    50         for(int i=0;i<N;i++)
    51         {
    52             if((pos = dic.find(list[i])) == notFound)
    53                 printf("0
    ");
    54             else
    55                 printf("%d
    ",pos->second);
    56         }
    57     }    
    58 }
  • 相关阅读:
    web.config中httpRedirect
    时间复杂度O(n)与空间复杂度O(1)
    NserviceBus过期处理
    struts的生命周期
    myeclipse 更改字体
    研磨struts2地址
    jQuery 实现公告无缝滚动
    统计网站访问图形数据链接
    工作经常使用的SQL整理
    使IE6下PNG背景透明的七种方法
  • 原文地址:https://www.cnblogs.com/helica/p/4783609.html
Copyright © 2011-2022 走看看