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
output
input
output
input
output
ViewCode
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
相关文章推荐
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard 水题
- Codeforces Round #293 (Div. 2) B. Tanya and Postcard
- Codeforces Round #293 (Div. 2) -- B. Tanya and Postcard
- Codeforces Round #324 (Div. 2) B. Kolya and Tanya
- Codeforces Round #288 (Div. 2) D.Tanya and Password(欧拉路径)
- B. Tanya and Postcard
- Codeforces Round #346 (Div. 2) C.Tanya and Toys
- CF Tanya and Postcard
- Codeforces Round #288 (Div. 2)---D. Tanya and Password
- 【Codeforces Round 324 (Div 2)B】【容斥】Kolya and Tanya 环上n个3元组至少有一组和不为6
- Codeforces Round #288 (Div. 2) D Tanya and Password
- Codeforces Round #288 (Div. 2)-D. Tanya and Password(欧拉路径及其打印)
- Codeforces Round #288 (Div. 2) D. Tanya and Password 欧拉回路
- Codeforces Round #288 (Div. 2)D.Tanya and Password——欧拉通路
- Codeforces #324 Div2 B.Kolya and Tanya(dp、思维)
- Codeforces Round #346 (Div. 2) C. Tanya and Toys
- Codeforces Round #288 (Div. 2) D. Tanya and Password (欧拉通路)
- Codeforces Round #288 (Div. 2) D. Tanya and Password
- Codeforces Round #346 (Div. 2)C. Tanya and Toys
- 518B - Tanya and Postcard【哎还是string】