[NYOJ] [1799] Borderlands 1

Problem Description

Loading...

Problem Analysis

The problem says sorting is not required —
in fact, the output follows the order in which each region first appears.
So we can open an extra array to keep track of that.

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include<stdio.h>
#include<string.h>
int a[120],b[120];
int main() {
    int cnt=0;
    memset(a,0,sizeof(a));
    memset(b,0,sizeof(b));
    int n,m;
    while(scanf("%d %d",&n,&m),n||m) {
        if(b[n])
            b[n]+=m;
        else {
            a[cnt++]=n;
            b[n]=m;
        }
    }
    for(int i=0; i<cnt; i++)
        printf("%d %d\n",a[i],b[a[i]]);
    return 0;
}
This post is licensed under CC BY-NC-SA 4.0. If it helped, or if you have anything to say, the comment box below is open.
Page views —
Unique visitors —

Loading...