ZeroJudge G796: Sorting Files

The company recently hired a new assistant named Xiaoming. On his first day, his boss asked him to help classify the just completed case files. Each case has a unique ID, consisting of six digits, with the last three digits representing its category number. Each set of ten consecutive category numbers will be grouped into the same folder.

For example, category numbers 000 to 009 are grouped into folder 0, category numbers 010 to 019 are grouped into folder 1, and so on. Therefore, if a file with the ID 103472 is received, it will be placed in folder 47.

Please help Xiaoming successfully complete his first day of classification work.

Sample Inputs/Outputs

Sample Input(s)Sample Output(s)
The input begins with an integer N (1 ≤ N ≤ 2000), representing the number of files. Following that, there are N lines each representing the ID of each file S_i (000000 ≤ S_i ≤ 999999, 1 ≤ i ≤ N).Output each folder number along with the number of files in that folder, separated by a single space. Only output the folder numbers where files are placed, and sort them in ascending order.
1
000000
0 1
5
232944
123941
201322
234941
231320
32 2
94 3
5
987012
342221
223120
126641
127643
1 1
12 1
22 1
64 2

Thought Process

You can use strings to store the file numbers and extract the third and fourth characters of the string, which represent the folder number.

Declare a map Map, where the key is the folder number and the value is the number of files in that folder. Each time you receive a file number, you increment Map[folder number]++.

Sample Code-ZeroJudge G796: Sorting Files

#include <iostream>
#include <map>
using namespace std;

int main() {
    cin.sync_with_stdio(0);
    cin.tie(0);
    int N;
    cin >> N;
    map<int, int>MAP;
    for (int i = 0; i<N; i++)
    {
        string str;
        cin >> str;
        string tmp = "";
        tmp += str[3];
        tmp += str[4];
        MAP[stoi(tmp)]++;
    }
    for (auto it:MAP)
    {
        cout << it.first << " " << it.second << "\n";
    }
}

//ZeroJudge G796
//Dr. SeanXD

Comments