Last active
December 26, 2017 13:50
-
-
Save wolfsyntax/41722cfbff5b7ebe038b56f2adf59bad to your computer and use it in GitHub Desktop.
ACM Problem Set Solution
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 <cstdio> | |
#include <set> | |
#include <map> | |
#include <cmath> | |
#include <cstdio> | |
#include <vector> | |
/** | |
Problem Link: https://www.hackerrank.com/contests/noi-ph-practice-page/challenges/copy-pasta/problem | |
Author (Source Code): Jayson Alpe => Wolf Syntax | |
**/ | |
using namespace std; | |
int main(){ | |
int t, n; scanf("%d",&t); | |
while(t--){ | |
scanf("%d",&n); | |
string tmp; | |
set<string>pasta; | |
map<string,int>baked; | |
map<string,int>inventory; | |
for(int i = 0; i < n; i++){ | |
cin >> tmp; | |
if(baked[tmp] == 1) | |
inventory[tmp]++; | |
if(baked[tmp] == 0) | |
baked[tmp] = 1; | |
pasta.insert(tmp); | |
} | |
vector<string> vec(pasta.begin(),pasta.end()); | |
if(inventory.size() == 0) | |
cout << "0" << endl; | |
else if(inventory.size() == 1) | |
cout << inventory[tmp] << endl; | |
else{ | |
int prev = 0, next = 1, dup = 0; | |
for(int i = 0; i < vec.size()-1; i++){ | |
if(inventory[vec[prev]] == inventory[vec[next]]){ | |
dup += inventory[vec[prev]]; | |
inventory[vec[prev]] = inventory[vec[next]] = 0; | |
break; | |
} else { | |
if(inventory[vec[prev]] == 0) prev += 2; | |
if(inventory[vec[next]] == 0) next++; | |
if(inventory[vec[prev]] != inventory[vec[next]]){ | |
if(inventory[vec[prev]] > inventory[vec[next]]){ | |
inventory[vec[prev]] -= inventory[vec[next]]; | |
dup += inventory[vec[next]]; | |
inventory[vec[next]] = 0; | |
}else { | |
inventory[vec[next]] -= inventory[vec[prev]]; | |
dup += inventory[vec[prev]]; | |
inventory[vec[prev]] = 0; | |
} | |
} | |
} | |
} | |
if(vec.size() > 1){ | |
if(inventory[vec[next]] != 0) dup += inventory[vec[next]]; | |
if(inventory[vec[prev]] != 0) dup += inventory[vec[prev]]; | |
} | |
cout << dup << 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> | |
using namespace std; | |
int main(){ | |
int n,ctr; | |
while(cin >> n){ | |
ctr = 1; | |
for(int nx = 0; nx < n; ctr++){ | |
for(int i = 0; i < ctr; i++){ | |
if(nx < n) cout << "PAK\n"; | |
nx++; | |
} | |
for(int i = 0; i < ctr; i++){ | |
if(nx < n) cout << "GANERN\n"; | |
nx++; | |
} | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment