HDOJ.1263

一道非常简单的map题吧

因为没做过hd的题所以输出格式爆炸



#include<bits/stdc++.h>

using namespace std;


int n;
int m;
map<pair<string,string>,int > mm;
int main()
{
	cin >> n;
	map<pair<string,string>,int >::iterator it;
	string ts1,ts2;
	int ti1;
	bool sign = false;
	while(n--)
	{
		
		cin >> m;
		mm.clear();
		for(int i=0;i<m;++i)
		{
			cin >> ts1 >> ts2 >> ti1;
			mm[make_pair(ts2,ts1)] += ti1;
		}
		ts1 = mm.begin()->first.first;
		cout <<ts1 ;
		for(it = mm.begin();it!=mm.end();++it)
		{
			if(it->first.first==ts1)
			{
			
				cout <<endl<<"   |----"<<it->first.second <<"("<<it->second << ")";
			}
			else
			{
				ts1 =  it->first.first;
				cout <<endl<< ts1;
				cout <<endl<<"   |----"<<it->first.second <<"("<<it->second << ")";
			}
		}
		if(n)	cout << endl<<endl;
		else cout <<endl;
	}

	return 0;
 } 
  • 两个数据之间居然要隔一行
  • map用下标查询还可以+=
  • 这题也可以用map 套map
原文地址:https://www.cnblogs.com/xxrlz/p/10380874.html