Weird Cryptography

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

Description

standard input/output

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

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.

/*/
统计输入相同字符串的个数,从小到大把字符串分组,每组内不能有相同字符串。 输出每组的字符串个数。 AC代码:
/*/
#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(x,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 - 简单的字符串处理的更多相关文章

  1. Redis的简单动态字符串实现

    Redis 没有直接使用 C 语言传统的字符串表示(以空字符结尾的字符数组,以下简称 C 字符串), 而是自己构建了一种名为简单动态字符串(simple dynamic string,sds)的抽象类 ...

  2. SQL点滴3—一个简单的字符串分割函数

    原文:SQL点滴3-一个简单的字符串分割函数 偶然在电脑里看到以前保存的这个函数,是将一个单独字符串切分成一组字符串,这里分隔符是英文逗号“,”  遇到其他情况只要稍加修改就好了 CREATE FUN ...

  3. 暑假练习赛 007 B - Weird Cryptography

    Weird Cryptography Description standard input/outputStatements Khaled was sitting in the garden unde ...

  4. Redis数据结构之简单动态字符串SDS

    Redis的底层数据结构非常多,其中包括SDS.ZipList.SkipList.LinkedList.HashTable.Intset等.如果你对Redis的理解还只停留在get.set的水平的话, ...

  5. 小白的Redis学习(一)-SDS简单动态字符串

    本文为读<Redis设计与实现>的记录.该书以Redis2.9讲解Redis相关内容.请注意版本差异. Redis使用C语言实现,他对C语言中的char类型数据进行封装,构建了一种简单动态 ...

  6. redis_简单动态字符串

    在redis中,C字符串(以'\0'结尾的字符数组)只用在一些无需对字符串值进行修改的地方,比如打印日志.其他情况,redis使用SDS - SimpleDynamicString 简单动态字符串,来 ...

  7. redis 系列3 数据结构之简单动态字符串 SDS

    一.  SDS概述 Redis 没有直接使用C语言传统的字符串表示,而是自己构建了一种名为简单动态字符串(simple dynamic string, SDS)的抽象类型,并将SDS用作Redis的默 ...

  8. 图解Redis之数据结构篇——简单动态字符串SDS

    图解Redis之数据结构篇--简单动态字符串SDS 前言     相信用过Redis的人都知道,Redis提供了一个逻辑上的对象系统构建了一个键值对数据库以供客户端用户使用.这个对象系统包括字符串对象 ...

  9. Redis中的简单动态字符串

    Redis没有直接使用C语言传统的字符串表示(以空字符结尾的字符数组,以下简称C字符串),而是自己构建了一种名为简单动态字符串(simple dynamic string,SDS)的抽象类型,并将SD ...

随机推荐

  1. volatile关键字与线程间通信

    >>Java内存模型 现在计算机普遍使用多处理器进行运算,并且为了解决计算机存储设备和处理器的运算速度之间巨大的差距,引入了高速缓存作为缓冲,缓存虽然能极大的提高性能,但是随之带来的缓存一 ...

  2. 在Eclipse中自定义类似syso的快捷代码模板

    sysout/syso syserr/ syse 点击菜单栏的“Window”->“Preferences”,打开“Preferences”对话框.在Preferences”对话框中点击“Jav ...

  3. 【翻译八】java-内存一致性错误

    Memory Consistency Errors Memory consistency errors occur when different threads have inconsistent v ...

  4. android 入门-工程属性介绍

    工程属性 (1)drawable-hdpi里面存放高分辨率的图片,如WVGA (480x800),FWVGA (480x854) (2)drawable-mdpi里面存放中等分辨率的图片,如HVGA ...

  5. Win10 资源文件

    ResourceLoader rl = new ResourceLoader(); DisOutText.Text = rl.GetString("Display"); Resou ...

  6. android 入门-Service实时向Activity通过BroadcastReceiver传递数据

    引文: http://www.cnblogs.com/linjiqin/p/3147764.html <RelativeLayout xmlns:android="http://sch ...

  7. web开发的步骤

    前端知道是浏览器呈现的部分,相对于前端,后台你可以理解为服务器端专门处理.读取.存储数据库数据的部分. 因为网站是基于B\S架构,即浏览器---服务端架构,就程序来讲,可笼统划分为前端程序和服务器端程 ...

  8. java-xml格式化

    参考:http://www.oschina.net/code/snippet_17793_4733 package com.ddatsh;   import java.io.IOException; ...

  9. Android UI学习 - Tab的学习和使用(转)

      本文是参考Android官方提供的sample里面的ApiDemos的学习总结.   TabActivity   首先Android里面有个名为TabActivity来给我们方便使用.其中有以下可 ...

  10. c文件操作 (转)

    文件文件的基本概念 所谓“文件”是指一组相关数据的有序集合. 这个数据集有一个名称,叫做文件名. 实际上在前面的各章中我们已经多次使用了文件,例如源程序文件.目标文件.可执行文件.库文件 (头文件)等 ...