Codeforces 525A - Vitaliy and Pie

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;
}

 

posted @ 2017-07-25 16:18  Wisdom+.+  阅读(275)  评论(0编辑  收藏  举报