题解 | 合并表记录
合并表记录
https://www.nowcoder.com/practice/de044e89123f4a7482bd2b214a685201
using System;
public class Program {
public static void Main() {
int count;
A[] a;
int x, y;
count = int.Parse(Console.ReadLine());
a = new A[count];
for (int i = 0; i < count; i++) {
var s = Console.ReadLine();
x = int.Parse(s.Split()[0]);
y = int.Parse(s.Split()[1]);
for (int j = 0; j <= i; j++) {
if (!a[j].flag) {
a[j].x = x;
a[j].y = y;
a[j].flag = true;
break;
} else if (a[j].x == x) {
a[j].y += y;
break;
}
}
}
Array.Sort(a,(c,b)=>c.x.CompareTo(b.x));
for (int i = 0; i < count; i++)
{
if( a[i].flag)
Console.WriteLine(a[i].x +" "+a[i].y);
}
}
public struct A {
public int x, y;
public bool flag;
}
}
汤臣倍健公司氛围 373人发布
查看18道真题和解析