Sort the Fabrics
InterviewTime limit20sMemory limit1024 MB
Count the fabrics that land in the same position when sorted by color (then ID) and by durability (then ID).
- Level
Easy3 of 10
- Topics
- Sorting, Implementation
- Solved
- No attempts yet
Problem
Each fabric has three properties:
- Color (): a string of lowercase English letters giving the color of the fabric.
- Durability (): an integer giving the durability of the fabric.
- Unique identifier (): an integer giving the ID of the fabric.
Ada and Charles work at the Kick Start fabric factory. Each day they receive fabrics, and one of them sorts the batch using these rules:
- Ada sorts in lexicographically increasing order by color ().
- Charles sorts in ascending order by durability ().
- Ties are broken by ascending order of the unique identifier ().
Given fabrics, count the fabrics that end up in the same position whether Ada or Charles sorts them.
Input
The first line contains the number of test cases . Then test cases follow.
Each test case begins with a line containing the integer , the number of fabrics. Then lines follow, each with a string , an integer , and an integer : the color, durability, and unique identifier of the -th fabric.
Output
For each test case, output one line in the form Case #x: y. Here is the test case number starting from 1, and is the number of fabrics that end up in the same position whether they are sorted by color or by durability.
Limits
- length of
- consists only of lowercase English letters.
- No two fabrics have the same .