Codeforces 525A

525A - Vitaliy and Pie

思路:贪心+hashing。

代码

#include<bits/stdc++.h>
using namespace std;
string s;
int Hash[26]={0};
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,ans=0;
    cin>>n>>s;
    for(int i=0;i<s.size();i++)
    {
        if(islower(s[i]))
        {
            Hash[s[i]-'a']++;
        }
        else
        {
            if(Hash[s[i]-'A'])Hash[s[i]-'A']--;
            else ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
原文地址:https://www.cnblogs.com/widsom/p/7234786.html