hdoj1263

没有算法,但比较麻烦的模拟题。。

#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
typedef struct Fruit{
	string name;
	string city;
	int count;
}Fruit;
bool cmp(Fruit a,Fruit b)
{
	if(a.city!=b.city)
		return a.city<b.city;
	return a.name<b.name;
}
int main()
{
	int n;
	bool flag=true;
	scanf("%d",&n);
	while(n--)
	{
		int i,m;
		scanf("%d",&m);
		Fruit f[110];
		for(i=1;i<=m;i++)
		{
			cin>>f[i].name>>f[i].city>>f[i].count;
		}
		sort(f+1,f+1+m,cmp);
		f[m+1].city=f[m].city;
		f[m+1].count=0;
		f[m+1].name="0";
		if(!flag)
			printf("\n");
		else
			flag=false;
		cout<<f[1].city<<endl;
		for(i=2;i<=m+1;i++)
		{
			if(f[i].city==f[i-1].city && f[i].name==f[i-1].name)
			{
				f[i].count+=f[i-1].count;
			}
			else if(f[i].city==f[i-1].city)
			{
				cout<<"   |----"<<f[i-1].name<<'('<<f[i-1].count<<')'<<endl;
			}
			else
			{
				cout<<"   |----"<<f[i-1].name<<'('<<f[i-1].count<<')'<<endl;
				cout<<f[i].city<<endl;
			}
		}
	}

//system("pause");
return 0;
}