hdu4287 水题

题意:   
      水题,就是给你一些单词,和一些按键记录,问打出下面的那些单词,每一个按键记录一共按了多少次。

思路: 

     直接把每个单词的每一位转换成数字,然后再把每个单词转换的数字转换成按键,然后按键记录++,为了节省空间我开的是map<int ,int>mark,直接开个num[1000000] 应该也可以吧;


#include<stdio.h>
#include<map>

#define N 5000 + 100

using namespace std;

int q[N];
//char str[N][10];
map<int ,int>ans;

int main ()
{
   int i ,j ,t ,n ,m ,num;
   char str[10];
   scanf("%d" ,&t);
   while(t--)
   {
      scanf("%d %d" ,&n ,&m);
      for(i = 1 ;i <= n ;i ++)
      scanf("%d" ,&q[i]);
      ans.clear();
      for(i = 1 ;i <= m ;i ++)
      {
         scanf("%s" ,str);
         int l = strlen(str) - 1;
         int tmp = 0;
         for(j = 0 ;j <= l ;j ++)
         {
             if(str[j] >= 'a' && str[j] <= 'c')
             num = 2;
             if(str[j] >= 'd' && str[j] <= 'f')
             num = 3;
             if(str[j] >= 'g' && str[j] <= 'i')
             num = 4;
             if(str[j] >= 'j' && str[j] <= 'l')
             num = 5;
             if(str[j] >= 'm' && str[j] <= 'o')
             num = 6;
             if(str[j] >= 'p' && str[j] <= 's')
             num = 7;
             if(str[j] >= 't' && str[j] <= 'v')
             num = 8;
             if(str[j] >= 'w' && str[j] <= 'z')
             num = 9;
             tmp = tmp * 10 + num;
          }
          ans[tmp]++;
      }
      for(i = 1 ;i <= n ;i ++)
      printf("%d
" ,ans[q[i]]);
   }
   return 0;
}

原文地址:https://www.cnblogs.com/csnd/p/12063247.html