A. Vitaliy and Pie 

题目大意:小写字母是钥匙,大写字母是门,字母相同的钥匙能开对应的门,从第一个门走到最后一个门,问至少要配多少钥匙才能走到最后

思路:扫一遍记录当前拥有的钥匙即可,如果手上没有这种钥匙那么配一把

 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<algorithm>
 5 #define maxn 200000
 6 char ch[maxn];
 7 using namespace std;
 8 int key[maxn];
 9 int main()
10 {
11     int n,ans=0;
12     scanf("%d",&n);
13     scanf("%s",ch+1);
14     for(int i=1;i<=n-1;i++)
15     {
16         key[ch[(i-1)*2+1]-'a']++;
17         int u=ch[(i-1)*2+2]-'A';
18         if(key[u]>0)key[u]--;else ans++;
19     }
20     printf("%d\n",ans);
21 }
View Code

相关文章:

  • 2021-05-17
  • 2022-01-25
  • 2021-08-18
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-05
  • 2021-08-12
猜你喜欢
  • 2022-02-20
  • 2021-07-01
  • 2021-06-01
  • 2021-12-18
  • 2022-02-04
  • 2022-01-06
  • 2022-02-11
相关资源
相似解决方案