Uva Problem ID: 12049 Just Prune The List

//Problem Link: http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3200 //Uva user Id: deepitauiu //this problem is very simple you just need to count total elements 1st array elements that is more then 2nd array and vice varsa . #include <bits/stdc++.h> using namespace std; int main() { int ans=0,i,j,k,c,f,t,n,m1; string key; cin>>t; while(t--){ map <string,int> m; cin>>n>>m1; ans=n; for(i=1;i<=n;i++) { cin>>key; //checking if the key is exsist in map if(m.count(key) != 0) { m[key]=m[key]+1; } // if the key is not exsist in map then initializing map else { m[key]=1; } } for(i=1;i<=m1;i++) { cin>>key; if(m.count(key) != 0) { //checking if the key is exsist in map then decreasing the key value if(m[key]>0) { m[key]=m[key]-1; ans-=1; } //if the key value is 0 that means 2nd array has more elements then 1st array so increasing ans else{ ans+=1; } } //checking if the key is not exsist in map that means new element in second array so increasing ans else { ans+=1; } } cout<<ans<<endl; } }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.