Logo
(追記) (追記ここまで)

12086번 - Moist (Small2) 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
5 초 512 MB31822512765.803%

문제

Moist has a hobby -- collecting figure skating trading cards. His card collection has been growing, and it is now too large to keep in one disorganized pile. Moist needs to sort the cards in alphabetical order, so that he can find the cards that he wants on short notice whenever it is necessary.

The problem is -- Moist can't actually pick up the cards because they keep sliding out his hands, and the sweat causes permanent damage. Some of the cards are rather expensive, mind you. To facilitate the sorting, Moist has convinced Dr. Horrible to build him a sorting robot. However, in his rather horrible style, Dr. Horrible has decided to make the sorting robot charge Moist a fee of \1ドル whenever it has to move a trading card during the sorting process.

Moist has figured out that the robot's sorting mechanism is very primitive. It scans the deck of cards from top to bottom. Whenever it finds a card that is lexicographically smaller than the previous card, it moves that card to its correct place in the stack above. This operation costs \1,ドル and the robot resumes scanning down towards the bottom of the deck, moving cards one by one until the entire deck is sorted in lexicographical order from top to bottom.

As wet luck would have it, Moist is almost broke, but keeping his trading cards in order is the only remaining joy in his miserable life. He needs to know how much it would cost him to use the robot to sort his deck of cards.

입력

The first line of the input gives the number of test cases, T. T test cases follow. Each one starts with a line containing a single integer, N. The next N lines each contain the name of a figure skater, in order from the top of the deck to the bottom.

Limits

  • 1 ≤ T ≤ 100.
  • Each name will consist of only letters and the space character.
  • Each name will contain at most 100 characters.
  • No name with start or end with a space.
  • No name will appear more than once in the same test case.
  • Lexicographically, the space character comes first, then come the upper case letters, then the lower case letters.
  • 1 ≤ N ≤ 100.

출력

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of dollars it would cost Moist to use the robot to sort his deck of trading cards.

제한

예제 입력 1

2
2
Oksana Baiul
Michelle Kwan
3
Elvis Stojko
Evgeni Plushenko
Kristi Yamaguchi

예제 출력 1

Case #1: 1
Case #2: 0

힌트

출처

Contest > Google > Google's Coding Competitions > Google APAC 2016 University Graduates Test > Practice Round APAC test 2016 C2번

Contest > Google > Google's Coding Competitions > Google of Greater China Test for New Grads of 2014 > Practice Round China New Grad Test 2014 C2번

Contest > Google > Google's Coding Competitions > EuroPython 2013 > EuroPython 2013 A2번

Contest > Google > Kick Start > Google Kick Start 2015 > Practice Round A2번

Contest > Google > Kick Start > Google Kick Start 2013 > Practice Round A2번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /