除了用链表还可以用STL中的map,^-^
#include<bits/stdc++.h>
using namespace std;
struct node
{
int x;
int y;
}stu[105];
map<int,int>s;
void f(string x)
{
int flag=1,t=0,j=1,m,n;
for(int i=0; i<(int)x.size(); i++)
{
if(x[i]=='-')
flag=0;
if(isdigit(x[i]))
t=t*10+(x[i]-'0');
if(x[i]==' '||i==x.size()-1)
{
if(j==1)
{
m=t;
if(!flag)
m=-m;
j++;
}
else if(j==2)
{
n=t;
if(!flag)
n=-n;
s[n]+=m;
j=1;
}
t=0;
flag=1;
}
}
}
bool cmp(node a,node b)
{
return a.x>b.x;
}
int main()
{
string x,y;
while(getline(cin,x))
{
s.clear();
f(x);
getline(cin,y);
f(y);
int j=0;
for(map<int,int>::iterator it=s.begin();it!=s.end();it++)
{
if(it->second !=0)
{
stu[j].x=it->first;
stu[j].y=it->second;
j++;
}
}
sort(stu,stu+j,cmp);
for(int i=0;i<j;i++)
printf("%d %d ",stu[i].y,stu[i].x);
printf("\n");
}
return 0;
}