Created
April 19, 2020 12:48
-
-
Save ABHIINAV12/0c5fe0f90bfb5ba6d7825a7feb18c81f 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
class Solution { | |
public: | |
string stoi(int a){ | |
if(a==0) | |
return "0"; | |
string ret=""; | |
while(a!=0){ | |
int r=a%10; | |
a/=10; | |
ret+='0'+r; | |
} | |
reverse(ret.begin(),ret.end()); | |
return ret; | |
} | |
int ano(string s){ | |
int r=0; | |
for(char c : s){ | |
r+=c-'0'; | |
r*=10; | |
} | |
return r/10; | |
} | |
vector<vector<string>> displayTable(vector<vector<string>>& o) { | |
vector<vector<string>> ret; | |
map<int,vector<string>> mp; | |
set<string> st; | |
for(auto it: o){ | |
mp[ano(it[1])].push_back(it[2]); | |
st.insert(it[2]); | |
} | |
vector<string> temp; | |
temp.push_back("Table"); | |
for(auto it : st) | |
temp.push_back(it); | |
ret.push_back(temp); | |
map<string, int> fp; | |
int num=0; | |
for(auto it : st){ | |
fp[it]=num; | |
num++; | |
} | |
for(auto it : mp){ | |
temp.clear(); | |
temp.push_back(stoi(it.first)); | |
vector<int> v(st.size()); | |
for(auto pp : it.second){ | |
v[fp[pp]]++; | |
} | |
for(auto pp : v) | |
temp.push_back(stoi(pp)); | |
ret.push_back(temp); | |
} | |
return ret; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment