Created
July 5, 2020 14:24
-
-
Save thepurpleowl/d1d1a21d674411f60977d821195fff20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// #include <iostream> | |
#include <bits/stdc++.h> | |
using namespace std; | |
bool cmp(pair<int,int> a, pair<int,int> b){ | |
return a.second> b.second; | |
} | |
void find_w(map<int,int> m){ | |
vector<pair<int,int>> arr; | |
for(auto i=m.begin();i!=m.end();i++){ | |
arr.push_back(make_pair(i->first,i->second)); | |
} | |
sort(arr.begin(),arr.end(),cmp); | |
cout<<arr[0].first<<endl; | |
} | |
int main() { | |
map<int, int> vote; | |
int n; | |
cin>>n; | |
for(int i=0;i<n;i++){ | |
int temp; | |
cin>>temp; | |
if(vote.find(temp)!=vote.end()){ | |
vote[temp] = vote[temp] +1; | |
} | |
else{ | |
vote[temp] = 1; | |
} | |
} | |
find_w(vote); | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <bits/stdc++.h> | |
using namespace std; | |
int main() { | |
// your code goes here | |
int n,x,y; | |
cin>>n; | |
vector<pair<int, int>> edges; | |
map<int, int> degree; | |
for(int i=0;i<n;i++){ | |
cin>>x>>y; | |
edges.push_back(make_pair(x,y)); | |
if(degree.find(x)!=degree.end()){ | |
degree[x] = degree[x] +1; | |
} | |
else{ | |
degree[x] = 1; | |
} | |
if(degree.find(y)!=degree.end()){ | |
degree[y] = degree[y] +1; | |
} | |
else{ | |
degree[y] = 1; | |
} | |
} | |
// for(auto it:degree){ | |
// cout<<it.first<<" "<<it.second<<endl; | |
// } | |
int k; | |
cin>>k; | |
int count = 0; | |
for(auto it: edges){ | |
if(degree[it.first]<k && degree[it.second]<k){ | |
// cout<<it.first<<" "<<it.second<<endl; | |
count++; | |
} | |
} | |
cout<<count<<endl; | |
return 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <bits/stdc++.h> | |
using namespace std; | |
string reverse(string demo){ | |
int n = demo.length(); | |
for(int i=0;i<n/2;i++){ | |
char temp = demo[i]; | |
demo[i] = demo[n-1-i];; | |
demo[n-1-i] = temp; | |
} | |
return demo; | |
} | |
void reverse_word(string temp){ | |
vector<string> reversed; | |
string str = ""; | |
for(auto ch: temp){ | |
if(ch==' '){ | |
reversed.push_back(reverse(str)); | |
str = ""; | |
} | |
else{ | |
str = str+ ch; | |
} | |
} | |
str = reversed[0]; | |
for(int i=1;i<reversed.size();i++){ | |
str = str+' '+reversed[i]; | |
} | |
cout<<str<<endl; | |
} | |
int main() { | |
// your code goes here | |
int n; | |
cin>>n; | |
for(int i=0;i<=n;i++){ | |
string temp; | |
getline(cin, temp); | |
// cout<<temp<<endl; | |
reverse_word(temp+' '); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment