stl 入门题目

一。Let the Balloon Rise 「map」

Contest time again! How excited it is to see balloons floating around. But to tell you a secret, the judges' favorite time is guessing the most popular problem. When the contest is over, they will count the balloons of each color and find the result.

This year, they decide to leave this lovely job to you. 

Input

Input contains multiple test cases. Each test case starts with a number N (0 < N <= 1000) -- the total number of balloons distributed. The next N lines contain one color each. The color of a balloon is a string of up to 15 lower-case letters. 

A test case with N = 0 terminates the input and this test case is not to be processed. 

Output

For each case, print the color of balloon for the most popular problem on a single line. It is guaranteed that there is a unique solution for each test case. 

Sample Input

5
green
red
blue
red
red
3
pink
orange
pink
0

Sample Output

red
pink
#include

using namespace std;
const int maxn=1e5+15;

map m;

int main(){
	int t,n;	int i,j,k;
	while(scanf("%d",&t)&&t){
		string s;
		int maxn=0;
		while(t--){
	
		string name;
		cin>>name;
		m[name]++;
		if(m[name]>maxn){
			maxn=m[name];
			s=name;
		}
	}
	cout<

二。水果统计

夏天来了~~好开心啊,呵呵,好多好多水果~~ 
Joe经营着一个不大的水果店.他认为生存之道就是经营最受顾客欢迎的水果.现在他想要一份水果销售情况的明细表,这样Joe就可以很容易掌握所有水果的销售情况了. 

Input

第一行正整数N(0 每组测试数据的第一行是一个整数M(0

Output

对于每一组测试数据,请你输出一份排版格式正确(请分析样本输出)的水果销售情况明细表.这份明细表包括所有水果的产地,名称和销售数目的信息.水果先按产地分类,产地按字母顺序排列;同一产地的水果按照名称排序,名称按字母顺序排序. 
两组测试数据之间有一个空行.最后一组测试数据之后没有空行. 

Sample Input

1
5
apple shandong 3
pineapple guangdong 1
sugarcane guangdong 1
pineapple guangdong 3
pineapple guangdong 1

Sample Output

guangdong
   |----pineapple(5)
   |----sugarcane(1)
shandong
   |----apple(3)
#include

using namespace std;
const int maxn=1e5+15;

map > m;

int main(){
	int t,n,k,i,j;
	string place,name;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		while(n--){
			cin>>name>>place;
			scanf("%d",&k);
			(m[place])[name]+=k;
		}
		for(map >::iterator it=m.begin();it!=m.end();it++){
			cout<first< ::iterator i=it->second.begin();i!=it->second.end();i++){
			cout<<"   |----";
			cout<first<<"("<second<<")"<

 

你可能感兴趣的:(STL)