Google Practice Round_C: Moist
来源:互联网 发布:平台优化 编辑:程序博客网 时间:2024/06/07 01:33
Problem
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.
Input
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.
Output
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.
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.
Small dataset
1 ≤ N ≤ 10.
Large dataset
1 ≤ N ≤ 100.
Sample
Output
2
2
Oksana Baiul
Michelle Kwan
3
Elvis Stojko
Evgeni Plushenko
Kristi Yamaguchi
Case #1: 1
Case #2: 0
备注:插入排序,计算插入次数,简单地一遍扫描就OK。
#include<stdio.h>#include<string.h>const int MAXSIZE = 105;int main(){freopen("C-small-2-attempt0.in", "r", stdin); freopen("C-small-2-attempt0-1.out", "w", stdout);int T;scanf("%d",&T);int caseid = 0;while(caseid<T){int N;int cost = 0;char s[MAXSIZE],currentMax[MAXSIZE];scanf("%d",&N);getchar();for(int i=0;i<N;i++){gets(s);if(i==0)strcpy(currentMax,s);if(strcmp(s,currentMax)<0)cost++;else if(strcmp(s,currentMax)>0)strcpy(currentMax,s);}printf("Case #%d: %d\n",caseid+1,cost);caseid++;}return 0;}
- Google Practice Round_C: Moist
- Moist-google
- Google Code Jam Notes - Moist - Java
- Moist - Practice Round China New Grad Test 2014 - 插入排序
- Google Practice Round_A: Bad Horse
- acdream 1146 Moist
- practice
- practice
- Google Practice Round China New Grad Test 2014
- Google APAC 2016 University Graduates Test Practice Round APAC test
- Moist (cin,getline的区别)
- [Practice Round APAC test 2016]Problem A. Bad Horse(Google 2016笔试题)
- Problem C. Not So Random Google APAC 2017 University Test Practice Round
- Problem A. Lazy Spelling Bee Google APAC 2017 University Test Practice Round
- Problem B. Robot Rock Band Google APAC 2017 University Test Practice Round
- Interview Practice
- java practice
- English Practice ...
- error : 'AddString' : is not a member of 'CWnd'
- DBCC CHECKDB用法 手工修复数据库
- JTabbedPane的扩展,可关闭,可预览(学习了)
- php preg_match正则函数的使用注意
- Windows批量添加防火墙例外端口的批处理代码
- Google Practice Round_C: Moist
- 自定义Android日期时间选择控件DateTimePickerDialog
- fatal error LNK1201
- 【Leetcode】Combination Sum II
- java.lang.NoSuchMethodError: javax.persistence.OneToMany.orphanRemoval()Z
- Thrift对多接口服务的支持
- 关于指针,数组指针,函数指针,指针的指针等面试题的详细攻略
- 为什么每个程序员都应该用Mac OS X?
- 百度云的离线下载