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. oracle 表查询(一)

    通过scott用户下的表来演示如何使用select语句,接下来对emp.dept.salgrade表结构进行解说. emp 雇员表字段名称   数据类型       是否为空   备注-------- ...

  2. AngularJS概念概述和第一个使用例子

    点击查看AngularJS系列目录 转载请注明出处:http://www.cnblogs.com/leosx/ 概念概述 本节使用一个简单的例子简要介绍了AngularJS的重要组成部分. 概念 描述 ...

  3. Mysql的排他锁和共享锁

    今天看代码看到有select name from user where id = 1 for update,有点懵逼,完全没有见过,只能说自己见识少了,那就只能学习一下.先做一下基本知识了解(大部分都 ...

  4. C语言定义从URL中获取键值的接口

    环境:centos7下,对客户端http请求进行解析,来获取有效键值(包括汉字). 头文件 /* 这是一份关于从Http请求信息中提取键值的接口声明的头文件 */ #ifndef _HEAD_H_ # ...

  5. Docker入门之七Dockerfile

    Dockerfile是一个文本格式的配置文本,可以使用它来创建自定义的镜像.首先我们可以先看一个dockerfile是什么样子.这里可以有一个网站不错:http://dockerfile.github ...

  6. sql sever 基础知识及详细笔记

    第六章:程序数据集散地:数据库 6.1:当今最常用的数据库 sql  server:是微软公司的产品 oracle:是甲骨文公司的产品 DB2:数据核心又称DB2通用服务器 Mysql:是一种开发源代 ...

  7. PHP连接SQL Server数据库

    服务环境:apache2.2 + PHP5.2 + Sql Server 2008 R2 一.所需库和工具1.SQLSRV20.EXE (php5.2版本对应的的Sql Server扩展库)注释:ph ...

  8. mysql中将时间转为秒

    项目中遇到的问题,需要将时间(时 分 秒)转为秒,业务上处理有些麻烦,尝试找了多种处理函数,然而并没有用 完美解决办法: TIME_TO_SEC   格式'HH:MM:SS'或HHMMSS SELEC ...

  9. ZOJ1654 Place the Robots

    Zoj1654 标准解法:二分匈牙利. 写法各异嘛,看不懂或者懒得看也正常,如果想了解我思路的可以和我讨论的. 在练习sap,所以还是写了一遍: #include<cstdio> #inc ...

  10. ZOJ3508 The War 贪心,最大流

    传送门:I Am Here 常规解法是贪心,但是在复习最大流的写法,因此用sap来写的.思路是很好想的 #include<cstdio> #include<cstdlib> # ...