HDU 4287 intelligent ime

Source: Internet
Author: User

Question:
Number of times the given number appears in the string (ing)

Analysis:
Direct Map <int, int> records the number given, and then each string can be converted into an integer (length less than 7), and then if the number is in the map,
Update the corresponding counter.

IfCodeError. Please point out ^

6726825 2012-09-09 17:10:30 Accepted 4287 93 ms 688 K 839 B G ++
View code

 1 # Include <iostream> 2 # Include <cstdio> 3 # Include <cstring>4 # Include <map> 5   6   Using   Namespace  STD;  7   8   Const   Int X = 5005  ;  9   10   Int  N, m;  11  Int  Use [x];  12   13   Int A [] = { 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  };  14   15 Map < Int , Int > Ma;  16   Char S [ 10  ];  17   18   Int  Main (){ 19 Freopen ( "  Sum. In  " , "  R  "  , Stdin );  20       Int  Ncase;  21 Scanf ( "  % D  " ,& Ncase ); 22       While (Ncase -- ){  23           Int  X;  24 Scanf ( "  % D  " , & N ,& M );  25   Ma. Clear ();  26 Memset (use, 0 ,Sizeof  (Use ));  27           For ( Int I = 1 ; I <= N; I ++ ){  28 Scanf ( "  % D  " ,& X );  29 Ma [x] = I;  30  }  31           Int  Temp;  32           For ( Int I = 0 ; I <m; I ++ ){  33 Scanf ( "  % S  "  , S );  34 Temp = 0 ;  35               For ( Int J = 0 ; S [J]; j ++ )  36 Temp = temp * 10 + A [s [J]- '  A  '  ];  37 Use [ma [temp] ++ ;  38  }  39           For ( Int I = 1 ; I <= N; I ++ )  40 Printf ( "  % D \ n  "  , Use [I]);  41   }  42       Return   0 ;  43 }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.