#include<iostream>#include<algorithm>usingnamespacestd;
struct Record
{
int Index;
int Value;
};
bool cmp(struct Record a,struct Record b)
{
return a.Index<b.Index;
}
int main()
{
struct Record array[100];
int N;
cin>>N;
for(int i=0;i<N;i++)
cin>>array[i].Index>>array[i].Value;
sort(array,array+N,cmp);
for(int i=0;i<N;i++)
{
if(array[i].Index==array[i+1].Index)
array[i+1].Value=array[i].Value+array[i+1].Value;
elsecout<<array[i].Index<<array[i].Value;
}
return0;
}
题目:合并表记录数据表记录包含表索引和数值,请对索引相同的记录进行合并,合并后表记录为相同索引表的数值求和。#include<iostream>#include<algorithm>using namespace std;struct Record{ int Index; int Value;};bool cmp(struct Record a,struct Record b