Skip to content

Instantly share code, notes, and snippets.

@Cycatz
Created January 31, 2017 16:17
Show Gist options
  • Save Cycatz/1afd353beecf738ea1fbe5015198967a to your computer and use it in GitHub Desktop.
Save Cycatz/1afd353beecf738ea1fbe5015198967a to your computer and use it in GitHub Desktop.
b291: 生態調查
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<map>
#include<set>
#include<vector>
using namespace std ;
vector<string> Vplace , Vanimal;
set<string> placeS , animalS;
map < pair <string , string> , int> quan ;
int main()
{
int testcase ;
scanf("%d" , &testcase);
getchar();
while(testcase--)
{
int idx = 1 , q ;
string data , pl , x , s;
getline(cin , s);
for(int i = 0 ; i < s.size() ; i++)
{
if(s[i] != ' ') x += s[i];
else{
if(idx == 1) data = x ;
if(idx == 2) q = atoi(x.c_str());
x = "";
idx++;
}
} pl = x ;
if(!animalS.count(pl))Vplace.push_back(pl);
if(!placeS.count(data))Vanimal.push_back(data);
animalS.insert(pl) , placeS.insert(data);
quan[make_pair(data , pl)] += q ;
}
for(int i = 0 ; i < Vplace.size() ; i++ )
{
cout << Vplace[i] << " :" ;
for(int j = 0 , k = 0 ; j < Vanimal.size() ; j++ )
{
if(quan.find(make_pair(Vanimal[j], Vplace[i])) == quan.end()) continue;
int dist = quan[make_pair(Vanimal[j], Vplace[i])];
k++ ? printf(", ") : printf(" ");
cout << Vanimal[j] << " " << dist ;
}
printf("\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment