Skip to content

Instantly share code, notes, and snippets.

@rishi93
Created April 6, 2016 07:06
Show Gist options
  • Save rishi93/ddf1f3e7ab2538b2a0c8c24f2af2708d to your computer and use it in GitHub Desktop.
Save rishi93/ddf1f3e7ab2538b2a0c8c24f2af2708d to your computer and use it in GitHub Desktop.
Sorting Bank Accounts - SBANK
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int t,n,testcase;
vector<string> bankList;
string acc,block;
cin>>t;
for(testcase=1; testcase<=t; testcase++){
bankList.clear();
cin>>n;
getline(cin,acc);//some sort of ghost line
for(int bankacc=0; bankacc<n; bankacc++){
getline(cin,acc);
bankList.push_back(acc);
}
sort(bankList.begin(),bankList.end());
int i = 0;
int j;
while(i<bankList.size()){
j = 1;
while(i+j < bankList.size() && bankList[i+j].compare(bankList[i]) == 0){
j += 1;
}
cout<<bankList[i]<<j<<endl;
i += j;
}
getline(cin,acc);//empty line after each testcase
cout<<endl;//empty line after each testcase
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment