01204212/scores

จาก Theory Wiki
ไปยังการนำทาง ไปยังการค้นหา
This is part of 01204212

Write a program that maintains scores for each team in a world-wide game competition.

Your program will read a list of names and additional scores and print out the current score of that team. Initially, every team has score of 0.

Input

First line: an integer M, the total number of updates (M <= 1,000,000) The number of teams will not be more than 100,000.

Next 'M lines: a team name which is a string consisting of 'A'-'Z','a'-'z','0'-'9' and '_' of length at most 20 and an additional score which is an integer of value at most 1,000.

Output

For each line of the input, output the current score of that team.

Examples

Input

5
hello 10
world 15
hello 123
Hello 15
Hello_world 100

Output

10
15
133
15
100

Test data

  • Get them here: [1]

Codes

You should modify the hash table code from 01204212/spreadsheet. Use the main class below.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

public class Main {

    HashTable table;
    
    public static void main(String[] args) throws IOException {
        Main m = new Main();
        
        m.process();
    }

    Main() {
        table = new HashTable();
    }
    
    private void process() throws IOException {
        BufferedReader reader = new BufferedReader(
                   new InputStreamReader(System.in) );

        int m = Integer.parseInt(reader.readLine());

        for(int i=0; i<m; i++) {
            String[] items = reader.readLine().split(" ");
            int additionalScore = Integer.parseInt(items[1]);
            int currentScore = table.get(items[0]) + additionalScore;
            
            System.out.println(currentScore);
            table.put(items[0],currentScore);
        }
    }
}