题解 | #合并表记录#
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
#include <stdio.h>
int maopao(int m[],int n[],int size)
{
int i=0,j=0,temp=0;
for(i=0;i<size-1;i++)
{
for(j=0;j<size-1;j++)
{
if(m[j]>m[j+1])
{
temp=m[j];
m[j]=m[j+1];
m[j+1]=temp;
temp=n[j];
n[j]=n[j+1];
n[j+1]=temp;
}
}
}
return 0;
}
int main()
{
int a[500]={0};
int b[500]={0};
int n=0;
int s=0;
int zhishi=1;
int index=0,val=0;
scanf("%d",&n);
int count=n;
for(int i=0;i<count;i++)
{
scanf("%d %d",&index,&val);
for(int j=0;j<s;j++)
{
if(a[j]==index)
{
b[j]+=val;
zhishi--;
}
}
if(zhishi==1)
{
a[s]=index;
b[s]=val;
s++;
}
zhishi=1;
}
maopao(a,b,s);
for(int z=0;z<s;z++)
{
printf("%d %d\n",a[z],b[z]);
}
}

