Ultraviolet A 10602-Editor Nottoobad

Source: Internet
Author: User


Meaning: There are n words to be input, and the first word must be input. Now there are two Commands: "repeat the last word" to copy the last word and "delete the last symbol" to delete the last letter of the last word. Ask how many times we need to input at least

Solution: 1: Thinking: Sorting + enumerating each word
2: because there are two commands, copy the last word and delete the last letter of the last word, and can be used infinitely, you only need to sort these words, then, judge the relationship between the current word and the previous word.

Code:
[Cpp]
# Include <algorithm>
# Include <iostream>
# Include <cstring>
# Include <string>
# Include <vector>
# Include <cstdio>
# Include <stack>
# Include <queue>
# Include <set>
Using namespace std;
# Define maxn110
 
Int t, n, ans;
String str [MAXN];
 
Void solve (){
Int I, j, k;
Sort (str, str + n); // sort
Ans = str [0]. size ();
For (I = 1; I <n; I ++) {// Enumeration
If (str [I] [0]! = Str [I-1] [0]) {
Ans + = str [I]. size ();
Continue;
}
For (j = 0, k = 0; j <str [I-1]. size (); j ++, k ++ ){
If (str [I-1] [j]! = Str [I] [k])
Break;
}
Ans + = str [I]. size ()-k;
}
Printf ("% d \ n", ans );
For (I = 0; I <n; I ++)
Cout <str [I] <endl;
}
 
Int main (){
// Freopen ("input.txt", "r", stdin );
Scanf ("% d", & t );
While (t --){
Scanf ("% d", & n );
For (int I = 0; I <n; I ++)
Cin> str [I];
Solve ();
}
Return 0;
}

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.