Weird Cryptography

Description

standard input/output
Statements

Khaled was sitting in the garden under an apple tree, suddenly! , well... you should guess what happened, an apple fell on his head! , so he came up with a new Cryptography method!! The method deals only with numbers, so... If you want to encode a number, you must represent each of its digits with a set of strings, then the size of the set is the digit itself, No set should contain the same string more than once. For example: the number 42, can be represented with the following two 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 two strings so it represent the digit 2. Given N strings, what is the smallest number you can get from dividing these strings into non-empty sets, and then decode the result by Khaled's Cryptography method? , You must use all 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 strings, then follows N space-separated string, each string will contain only lower-case English letters, and the length of each string will not exceeded 100. You can assume that there are no more than nine distinct strings among the given strings. A line containing the number 0 defines the end of the input you should not process this line.

Output

For each test case print a single line in the following format: "Case c: x"   where c is the test case number starting from 1 and x is the solution to the described problem above.

Sample Input

 

Input
3 one two two
7 num go book go hand num num
25 aa aa aa aa aa aa aa aa 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: 1111111111111111111111111

Sample Output

 

Hint

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

/*
将单词放进set中会返回一个数,给出n个单词,任意放进set中,让你求返回的数字组成最小数字 思路:先排序,第一次,全放,然后每种个数减一,再放进去,再每种个数减一,以此类推,得出第i大的数字
*/
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<map>
#define N 10010
using namespace std;
bool cmp(int s1,int s2)
{
if(s1>s2)
return true;
return false;
}
vector<string >v;
int ans[N];
int n;
string s;
int cur[N];
int main()
{
//freopen("in.txt","r",stdin);
int p=;
while(true)
{
v.clear();
int len=;
scanf("%d",&n);
memset(ans,,sizeof ans);
memset(cur,,sizeof cur);
if(!n) break;
//for(int i=0;i<=n;i++)
// cout<<ans[i]<<" ";
//cout<<endl;
for(int i=;i<n;i++)
{
cin>>s;
v.push_back(s);
}
sort(v.begin(),v.end());
//cout<<"ok"<<endl;
for(int i=;i<n-;i++)
{
if(v[i]==v[i+])
ans[len]++;
else
ans[len++]++;
}
if(v[n-]==v[n-])
ans[len]++;
else
ans[++len]++;
int maxn=-;
for(int i=;i<=len;i++)
{
if(maxn<ans[i])
maxn=ans[i];
for(int j=;j<ans[i];j++)
cur[j]++;
}
//cout<<"len="<<len<<endl;
//for(int i=0;i<=len;i++)
// cout<<ans[i]<<" ";
//cout<<endl;
//cout<<"len="<<len<<endl;
printf("Case %d: ",p++);
for(int i=maxn-;i>=;i--)
printf("%d",cur[i]);
printf("\n");
//cout<<endl;
}
return ;
}

暑假练习赛 007 B - Weird Cryptography的更多相关文章

  1. 暑假练习赛 007 E - Pairs

    E - Pairs Description standard input/outputStatements In the secret book of ACM, it’s said: “Glory f ...

  2. 暑假练习赛 007 C - OCR

    C - OCR Description standard input/outputStatements Optical Character Recognition (OCR) is one of th ...

  3. 暑假练习赛 007 A - Time

    A - Time Description standard input/outputStatements A plane can go from city X to city Y in 1 hour ...

  4. ACM: Gym 100935B Weird Cryptography - 简单的字符串处理

    Weird Cryptography Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u ...

  5. 暑假练习赛 003 F Mishka and trip

    F - Mishka and trip Sample Output   Hint In the first sample test: In Peter's first test, there's on ...

  6. 暑假练习赛 003 B Chris and Road

    B - Chris and Road Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144K ...

  7. 暑假练习赛 003 A Spider Man

    A - Spider Man Crawling in process... Crawling failed Time Limit:2000MS     Memory Limit:262144KB    ...

  8. 暑假练习赛 006 B Bear and Prime 100

    Bear and Prime 100Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB ...

  9. 暑假练习赛 006 E Vanya and Label(数学)

    Vanya and LabelCrawling in process... Crawling failed Time Limit:1000MS     Memory Limit:262144KB    ...

随机推荐

  1. js学习要点

    js 一.词法结构 1.区分大小写 2.注意 // 单行 /* 多行注释 */ 3.字面量(直接量 literal) 12 //数字 5.8 // 小数 "hello" 'hell ...

  2. ThinkPHP中:检查Session是否过期

    1.创建Session public function index(){ $sess_time=time(); session('name','andy'); session('time_stamp' ...

  3. HSF服务的开发与使用

    1.HSF服务的开发 1) 基于Maven创建一个web工程HSFService,如下图,其他的可以自定义. 2)创建好好在src/main目录下创建一个java目录,并将其设置为sources fo ...

  4. [USACO 3.3.1]骑马修栅栏t

    [USACO 3.3.1]骑马修栅栏 时间限制: 1 Sec  内存限制: 64 MB提交: 39  解决: 17[提交][状态][讨论版] 题目描述 农民John每年有很多栅栏要修理.他总是骑着马穿 ...

  5. 天上掉Pizza

    天上掉Pizza 时间限制: 3 Sec  内存限制: 128 MB提交: 73  解决: 48[提交][状态][讨论版] 题目描述 明明喜欢Pizza,但总是缺钱.有一天,他在报纸上阅读,他最喜爱的 ...

  6. 移动端效果之Swiper

    写在前面 最近在做移动端方面运用到了饿了么的vue前端组件库,因为不想单纯用组件而使用它,故想深入了解一下实现原理.后续将会继续研究一下其他的组件实现原理,有兴趣的可以关注下. 代码在这里:戳我 1. ...

  7. ajax url参数中文乱码解决方法

    较好的处理办法,对js的url中的中文参数值使用两次encodeURI(),即encodeURI(encodeURI("url的中文参数值")) JS代码: var name=&q ...

  8. HDU1085 多重背包

    Holding Bin-Laden Captive! Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Ja ...

  9. javascript字符串对象

    String字符串对象 1. 字符串粗体展示: var a = "陈冠希喜欢拍电影";   document.writeln(a.bold()+"<br/>& ...

  10. RewriteMap(apache)

    最近在工作中发现一个陌生的语法,apache服务器站点rewrite配置文件里的,开始还以为是apache的一种新语法,以这个词网上搜索,没搜到相关文章,跟老同事请教了一下,说这个是RewriteMa ...