您的位置:首页 > 其它

Codeforces Round #293 (Div. 2)——B——Tanya and Postcard

2015-03-19 12:54 399 查看
LittleTanyadecidedtopresentherdadapostcardonhisBirthday.Shehasalreadycreatedamessage—stringsoflengthn,consistingofuppercaseandlowercaseEnglishletters.Tanyacan'twriteyet,soshefoundanewspaperanddecidedtocutoutthelettersandgluethemintothepostcardtoachievestrings.Thenewspapercontainsstringt,consistingofuppercaseandlowercaseEnglishletters.Weknowthatthelengthofstringtgreaterorequaltothelengthofthestrings.

Thenewspapermaypossiblyhavetoofewofsomelettersneededtomakethetextandtoomanyofsomeotherletters.That'swhyTanyawantstocutsomenlettersoutofthenewspaperandmakeamessageoflengthexactlyn,sothatitlookedasmuchaspossiblelikes.Iftheletterinsomepositionhascorrectvalueandcorrectlettercase(inthestringsandinthestringthatTanyawillmake),thensheshoutsjoyfully"YAY!",andiftheletterinthegivenpositionhasonlythecorrectvaluebutitisinthewrongcase,thenthegirlsays"WHOOPS".

Tanyawantstomakesuchmessagethatletshershout"YAY!"asmuchaspossible.Iftherearemultiplewaystodothis,thenhersecondpriorityistomaximizethenumberoftimesshesays"WHOOPS".YourtaskistohelpTanyamakethemessage.

Input
Thefirstlinecontainslines(1 ≤ |s| ≤ 2·105),consistingofuppercaseandlowercaseEnglishletters—thetextofTanya'smessage.

Thesecondlinecontainslinet(|s| ≤ |t| ≤ 2·105),consistingofuppercaseandlowercaseEnglishletters—thetextwritteninthenewspaper.

Here|a|meansthelengthofthestringa.

Output
Printtwointegersseparatedbyaspace:

thefirstnumberisthenumberoftimesTanyashouts"YAY!"whilemakingthemessage,

thesecondnumberisthenumberoftimesTanyasays"WHOOPS"whilemakingthemessage.

Sampletest(s)

input
AbC
DCbA


output
30


input
ABC
abc


output
03


input
abacaba
AbaCaBA


output
34
大意:统计两次,把第二个串当模板,用第一个串去比较,第一次记录相同的字母(符号和大小写相同),统计过的就拿出,第二次不管大小写,看字母是否一样。


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
usingnamespacestd;
constintMAX=222222;
chars[MAX],t[MAX],visit[MAX];
intmain()
{
inta[200];
cin>>s>>t;
intn,m;
n=m=0;
memset(a,0,sizeof(a));
intn1=strlen(s);
intn2=strlen(t);
memset(visit,0,sizeof(visit));
for(inti=0;i<n2;i++)
a[t[i]]++;
for(inti=0;i<n1;i++){
if(a[s[i]]){
a[s[i]]--;
n++;
visit[i]=1;
}
}
for(inti=0;i<n1;i++){
if(visit[i])continue;
if(s[i]>='a'&&s[i]<='z'){
if(a[s[i]-'a'+'A']){
a[s[i]-'a'+'A']--;
m++;
}
}
elseif(s[i]>='A'&&s[i]<='Z'){
if(a[s[i]-'A'+'a']){
a[s[i]-'A'+'a']--;
m++;
}
}
}
printf("%d%d\n",n,m);
return0;
}


ViewCode


                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: