My issue
plz fix the error…
My code
#include <bits/stdc++.h>
#include<set>
#include<string>
using namespace std;
int main() {
// your code goes here
int t;
cin>>t;
while(t--){
string a,b;
cin>>a>>b;
int n;
cin>>n;
a=a+b;
set<char>sp;
for(auto x:a){
sp.insert(x);
}
set<char>s;
for(int i=0;i<n;i++){
string strpy;
cin>>strpy;
for(auto v:strpy){
s.insert(v);
}
}
int z=s.size();
int count=0;
for(auto p:s){
if(sp.find(p)!=sp.end()){
count++;
}
}
if(z==count) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
return 0;
}
Problem Link: NAME1 Problem - CodeChef
@deepakjdh31
Your code will fail in case of multiple frequency .
like having aabb multiple times .
so to manage this problem u can use map instead of set.
like this
#include<bits/stdc++.h>
using namespace std;
void solve() {
string a, b;
cin >> a >> b;
map<char,int> mp, mpChild;
for(int i=0; i<a.size(); i++){
mp[a[i]]++;
}
for(int i=0; i<b.size(); i++){
mp[b[i]]++;
}
int n;
cin >> n;
string name;
for(int i=0; i<n; i++){
cin >> name;
for(int j=0; j<name.size(); j++){
mpChild[name[j]]++;
if (mpChild[name[j]] > mp[name[j]]){
cout << "NO" << endl;
return;
}
}
}
cout << "YES" << endl;
}
int main() {
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}
u code not accepted or submit .
@deepakjdh31
Here u go buddy
#include<bits/stdc++.h>
using namespace std;
void solve() {
string a, b;
cin >> a >> b;
map<char,int> mp, mpChild;
for(int i=0; i<a.size(); i++){
mp[a[i]]++;
}
for(int i=0; i<b.size(); i++){
mp[b[i]]++;
}
int n;
cin >> n;
string name;
int ch=0;
for(int i=0; i<n; i++){
cin >> name;
for(int j=0; j<name.size(); j++){
mpChild[name[j]]++;
if (mpChild[name[j]] > mp[name[j]]){
ch=1;
}
}
}
if(ch)
cout << "NO" ;
else
cout<< "YES";
cout<<endl;
}
int main() {
int t;
cin >> t;
while(t--) {
solve();
}
return 0;
}