Category : mapping

#include<bits/stdc++.h> using namespace std; int main () { int flag=0,i; string s1,s2,s3; map<char,int > m1,m2; getline(cin,s1); getline(cin,s2); getline(cin,s3); for(i=0;i<s1.size();i++) { m1[s1[i]]++; } for(i=0;i<s2.size();i++) { m1[s2[i]]++; } for(i=0;i<s3.size();i++) { m2[s3[i]]++; } for(auto itr=m1.begin();itr!=m1.end();itr++) { if(m1[itr->first]<m2[itr->first]){ flag=1; break;} } if(flag==1) cout<<"NO n"; else cout<<"YES n"; return 0; } link of question :-https://codeforces.com/problemset/problem/141/A?mobile=true test case:- ————— JUTCN —————– ..

Read more

#include<bits/stdc++.h> using namespace std; #define ll long long int #define rep(i,a,b) for(ll i=a;i<b;i++) void calculation(ll n,ll x) { ll i,arr[n],k,max=INT_MIN,j=0,min=INT_MAX; map<ll,ll> m1,m2; rep(i,0,n) { cin>>arr[i]; m1[arr[i]]++; } if(x==0) { rep(i,0,n) { if(m1[arr[i]]>max) max=m1[arr[i]]; } cout<<max<<" 0n"; } else{ rep(i,0,n) { if(m1[arr[i]]+m2[arr[i]]>=max && m2[arr[i]]<min){ max=m1[arr[i]]+m2[arr[i]]; min=m2[arr[i]];} } cout<<max<<" "<<min<<"n"; } } int main () { ll ..

Read more

I’m trying to create a map of integers that trigger function calls but keep getting an error "expression preceding parentheses of apparent call must have (pointer-to-) function type" in my test.h: #include <map> class test { public: void accepted(); void Outputs(); typedef void (test::* m_method)(void); std::map<int, m_method> sw_op_mode_map; }; and in my test.cpp: #include <iostream> ..

Read more

How can I loop, access and assign through a std::map in C++? My map is defined as: std::map<std::string, std::map<std::string, int>> For example, the above container holds data like this: m["country"]["capital"] = value; m["country1"]["capital1"] = value; m["country2"]["capital2"] = value; based on the country and capital,weather value gets updated at present if and map is used map<string,int>mp; ..

Read more

I’ve read that std::map is often used to map function’s pointers but i don’t really understand how it works, here is the code where i would use that: // here go all the functions to call int main() { std::array<bool, 4> exercises; int chosenExercise; exercises.fill(false); do { std::cout << "Type the exercise’s number you want ..

Read more