1039. 到底买不买(20):map应用

来源:互联网 发布:流量联网控制软件 编辑:程序博客网 时间:2024/05/22 10:52
#include<iostream>#include<map>#include<string>using namespace std;int main(){    map<char,int>M1, M2;    char C;    int ans;    string str1, str2;    while(cin>>str1>>str2)    {        ans=0;        for( int i=0, C='0'; i<10; i++ ){                M1[C]=0;                M2[C]=0;                C++;        }        for( int i=0, C='A'; i<26; i++ ){                M1[C]=0;                M2[C]=0;                C++;         }        for( int i=0, C='a'; i<26; i++ ){                M1[C]=0;                M2[C]=0;                C++;         }        for( int i=0; i<str1.size(); i++ )        {               M1[str1[i]]++;        }        for( int i=0; i<str2.size(); i++ )        {               M2[str2[i]]++;        }        map<char,int>::iterator it, it2;        for(  it=M1.begin(), it2=M2.begin(); it!=M1.end(), it2!=M2.end() ; it++, it2++ )        {            if(  it2->second > it->second )            {                ans += it2->second - it->second;            }        }        if(ans!=0)            cout<<"No "<<ans<<endl;        else            cout<<"Yes "<<str1.length()-str2.length()<<endl;    }    return 0;}

0 0