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 }