Acm:gym 100935B Weird Cryptography-Simple string handling

Source: Internet
Author: User

Weird CryptographyTime limit:2000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U Gym 100935B

Description

Standard Input/output

Khaled is sitting in the garden under an apple tree, suddenly! , well ... should guess what happened, a Apple fell on his head! , so he came up with a new cryptography method!! The method deals only with numbers ... If you want to encode a number, you must represent each of their digits with a set of strings and then the size of the set is T He digit itself, No set should contain the same string more than once. For example:the number, can is represented with the following and the Sets:1) "Dog" "Load" "under" "Nice". 2) "Stack" "dog". The first set contain four strings so it represent the digit 4. The second set contain the strings so it represent the digit 2. Given N strings, what's the smallest number can get from dividing these strings to Non-empty sets, and then decode The result by Khaled ' s cryptography method? , you must the given strings, and no set should contain the same string more than once.

Input

The input consists of several test cases, each test case starts with 0 < N ≤10000, the number of the given Strin GS, then follows N space-separated string, each string would contain only lower-case 中文版 letters, and the length of EAC H string would not exceeded 100. You can assume that there is no more than nine distinct strings among the given strings. A line containing the number 0 defines the end of the "input" is should not the "process".

Output

For each test case, print a single line in the following format: ' Case c:x ' where C is the ' test Case number starting fro M 1 and X are the solution to the described problem above.

Sample Input

Input
3 One and both
7 num Go book go hand num num
+ AA aa aa aa aa aa AA, AA, AA aa aa AA, AA, AA, AA AA, AA
0
Output
Case 1:12
Case 2:124
Case 3:1.,111,111,111,111,11e,+24

Hint

In the first sample, we divided the given strings into the sets, the first set contains the word: "One" and "II" so I T represents the digit 2, the second set contains only one word: "Both" so it represent the digit 1.

/* /Statistics input the number of the same string, from small to a lot of string grouping, each group can not have the same string. Outputs the number of strings per group. AC Code:/*

#include "algorithm" #include "iostream" #include "CString" #include "cstdlib" #include "Cstdio" #include "string" # Include "vector" #include "queue" #include "Cmath" using namespace std;typedef long long LL; #define MEMSET (x, y) memset (x, Y, sizeof (x)) #define memcpy (y) memcpy (x,y,sizeof (x)) string S[10005];int Main () {int N,time=1;int num[10005],ans[10005] ; while (~scanf ("%d", &n)) {if (!n) Break;memset (ans,0); for (int i=0; i<n; i++) {cin>>s[i];num[i]=1;} Sort (s,s+n); int j=0;for (int i=1; i<=n; i++) {if (s[i]==s[i-1]) Num[j]++;else j + +;} int maxx=0;for (int i=0;i<j;i++) {Maxx=max (Num[i],maxx); for (int k=0;k<num[i];k++) {ans[k]++;}} printf ("Case%d:", time++); for (int i=maxx-1;i>=0;i--) {printf ("%d", Ans[i]);} Puts ("");} return 0;}

  

Acm:gym 100935B Weird Cryptography-Simple string handling

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.