【PAT甲级】1092 To Buy or Not to Buy (20 分)

Meaning of the questions:

Two lines of character string, if the character string included in the first row of the second line of the string, the output of "Yes" and the first line of the character string by subtracting the number of remaining second line character string, and otherwise outputs "No" and the second (the same characters may appear several times, the number of sensitive) not in the first two rows of the row number of the string of characters in the string.

Code:

#define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
string s1,s2;
int num[307],vis[307];
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>s1>>s2;
int sum=0;
for(int i=0;i<s2.size();++i){
++num[s2[i]-'0'];
vis[s2[i]-'0']=1;
}
int cnt=0;
for(int i=0;i<s1.size();++i){
if(vis[s1[i]-'0']){
if(num[s1[i]-'0']>0)
--num[s1[i]-'0'];
else
++cnt;
}
else
++cnt;
}
int flag=0;
for(int i=0;i<300;++i){
if(num[i]>0) {
flag = + num [i];
}
}
if(flag)
cout<<"No "<<flag;
else
cout<<"Yes "<<cnt;
return 0;
}

Guess you like

Origin www.cnblogs.com/ldudxy/p/11908393.html