CodeForces - 43B Letter

字符串的处理

统计已有字符的个数 和需求字符比较

 1 #include <iostream>
 2 #include <stdio.h>
 3 #include <string.h>
 4 
 5 using namespace std;
 6 
 7 int head[64];
 8 int text[64];
 9 char input[256];
10 int main()
11 {
12     freopen("in.txt", "r", stdin);
13     gets(input);
14     for (int i = 0; i < strlen(input); i++)
15     {
16         if (input[i] >= 'a' && input[i] <= 'z')
17         {
18             head[input[i] - 'a']++;
19         }
20         else if ( input[i] >= 'A' && input[i] <= 'Z' )
21         {
22             head[input[i] - 'A'+26]++;
23         }
24     }
25     gets(input);
26     for (int i = 0; i < strlen(input); i++)
27     {
28         if (input[i] >= 'a' && input[i] <= 'z')
29         {
30             text[input[i] - 'a']++;
31         }
32         else if ( input[i] >= 'A' && input[i] <= 'Z' )
33         {
34             text[input[i] - 'A'+26]++;
35         }
36     }
37     bool judge = true;
38     for (int i = 0; i < 52; i++)
39     {
40         if (text[i] > head[i] )
41         {
42             judge = false;
43             break;
44         }
45     }
46     if (judge) printf("YES\n");
47     else printf("NO\n");
48 }

 

posted @ 2017-01-21 00:06  Lorazepam  阅读(231)  评论(0编辑  收藏  举报