Google test (2015/8/6)

Source: Internet
Author: User

Huadian North Wind Blows
Key laboratory of cognitive computing and application, Tianjin University
Date: 2015/8/16

Problem 1:

Problem 2:

Problem 3:
Moist has a hobby – collecting figure skating trading cards. His card collection have been growing, and it's now too large to keep in one disorganized pile. Moist needs to sort the "cards in alphabetical order" so "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 off his hands, and the sweat causes per Manent damage. Some of the cards is rather expensive, mind you. To facilitate the sorting, moist have convinced Dr horrible to build him a sorting robot. However, in his rather horrible style, Dr horrible have 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 have 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's 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 are so RTed in lexicographical order from top to bottom.
As wet luck would has it, moist is almost broke, but keeping he trading cards in order was the only remaining joy in his Miserable life. He needs to know what 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 num ber of dollars it would cost moist to use the robot to sort his deck of trading cards.
Limits
1≤t≤100.
Each name is consist of only letters and the space character.
Each name is contain at the most characters.
No name with start or end with a space.
No name would appear more than once in the same test case.
Lexicographically, the space character comes first, then come the upper case letters and then the lower case letters.
Small DataSet
1≤n≤10.
Large DataSet
1≤n≤100.
Sample
Input
2
2
Oksana Baiul
Michelle Kwan
3
Elvis Stojko
Evgeni Plushenko
Kristi Yamaguchi
Output
Case #1:1
Case #2:0

#include <iostream>#include <string>#include <vector>#include <ostream>#include <fstream>using namespace STD;intMainintargcChar* argv[]) {Ifstream in ("C:\\users\\zhengyi\\desktop\\consoleapplication1\\debug\\input.txt"); Streambuf *cinbuf =Cin. Rdbuf ();//save old buf    Cin. Rdbuf (In.rdbuf ());//redirect std::cin to in.txt!Ofstream Out ("C:\\users\\zhengyi\\desktop\\consoleapplication1\\debug\\out.txt"); Streambuf *coutbuf =STD::cout. Rdbuf ();//save old buf    cout. Rdbuf (Out.rdbuf ());//redirect std::cout to out.txt!    //std::cin.rdbuf (CINBUF); Reset to standard input again    //std::cout.rdbuf (COUTBUF);//reset to standard output again    intNCin>> N; for(inti =0; i < N; i++) {intNCin>> N;intCount =0;Cin. Clear ();stringStr vector<string>v1; while(Getline (Cin, str)) {count++; V1.push_back (str);if(Count > N) Break; } v1.erase (V1.begin ());intCost =0; for(intK =1; K < n; k++) {stringkey = V1[k];intt = k-1;if(T >=0&& v1[t].compare (key) >0) {v1[t +1] = V1[t];                t--;            cost++; } v1[t +1] = key; }cout<<"Case #"<< i+1<<":"<< cost << Endl; }return 0;}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Google test (2015/8/6)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.