ACM: Gym 100935B Weird Cryptography - 简单的字符串处理
Description
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
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
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 - 简单的字符串处理的更多相关文章
- Redis的简单动态字符串实现
Redis 没有直接使用 C 语言传统的字符串表示(以空字符结尾的字符数组,以下简称 C 字符串), 而是自己构建了一种名为简单动态字符串(simple dynamic string,sds)的抽象类 ...
- SQL点滴3—一个简单的字符串分割函数
原文:SQL点滴3-一个简单的字符串分割函数 偶然在电脑里看到以前保存的这个函数,是将一个单独字符串切分成一组字符串,这里分隔符是英文逗号“,” 遇到其他情况只要稍加修改就好了 CREATE FUN ...
- 暑假练习赛 007 B - Weird Cryptography
Weird Cryptography Description standard input/outputStatements Khaled was sitting in the garden unde ...
- Redis数据结构之简单动态字符串SDS
Redis的底层数据结构非常多,其中包括SDS.ZipList.SkipList.LinkedList.HashTable.Intset等.如果你对Redis的理解还只停留在get.set的水平的话, ...
- 小白的Redis学习(一)-SDS简单动态字符串
本文为读<Redis设计与实现>的记录.该书以Redis2.9讲解Redis相关内容.请注意版本差异. Redis使用C语言实现,他对C语言中的char类型数据进行封装,构建了一种简单动态 ...
- redis_简单动态字符串
在redis中,C字符串(以'\0'结尾的字符数组)只用在一些无需对字符串值进行修改的地方,比如打印日志.其他情况,redis使用SDS - SimpleDynamicString 简单动态字符串,来 ...
- redis 系列3 数据结构之简单动态字符串 SDS
一. SDS概述 Redis 没有直接使用C语言传统的字符串表示,而是自己构建了一种名为简单动态字符串(simple dynamic string, SDS)的抽象类型,并将SDS用作Redis的默 ...
- 图解Redis之数据结构篇——简单动态字符串SDS
图解Redis之数据结构篇--简单动态字符串SDS 前言 相信用过Redis的人都知道,Redis提供了一个逻辑上的对象系统构建了一个键值对数据库以供客户端用户使用.这个对象系统包括字符串对象 ...
- Redis中的简单动态字符串
Redis没有直接使用C语言传统的字符串表示(以空字符结尾的字符数组,以下简称C字符串),而是自己构建了一种名为简单动态字符串(simple dynamic string,SDS)的抽象类型,并将SD ...
随机推荐
- yum -y list java* 查看当前java的版本
[root@NB ok]# yum -y list java* Loaded plugins: fastestmirror, refresh-packagekit, security Loading ...
- Asp.Net - 9.socket(聊天室)
9.1 Socket相关概念 IP地址 每台联网的电脑都有一个唯一的IP地址. 长度32位,分为四段,每段8位,用十进制数字表示,每段范围 0 ~ 255 特殊IP:127.0.0.1 用户本地网卡测 ...
- JAVA基础学习之final关键字、遍历集合、日期类对象的使用、Math类对象的使用、Runtime类对象的使用、时间对象Date(两个日期相减)(5)
1.final关键字和.net中的const关键字一样,是常量的修饰符,但是final还可以修饰类.方法.写法规范:常量所有字母都大写,多个单词中间用 "_"连接. 2.遍历集合A ...
- Acdream 1111:LSS(水题,字符串处理)
LSS Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 128000/64000 KB (Java/Others) SubmitStati ...
- Howto: Connect MySQL server using C program API under Linux or UNIX
From my mailbag: How do I write a C program to connect MySQL database server? MySQL database does su ...
- 最长公共子序列(LCS)和最长递增子序列(LIS)的求解
一.最长公共子序列 经典的动态规划问题,大概的陈述如下: 给定两个序列a1,a2,a3,a4,a5,a6......和b1,b2,b3,b4,b5,b6.......,要求这样的序列使得c同时是这两个 ...
- Mesa 3D
Mesa 3D是一个在MIT许可证下开放源代码的三维计算机图形库,以开源形式实现了OpenGL的应用程序接口. OpenGL的高效实现一般依赖于显示设备厂商提供的硬件,而Mesa 3D是一个纯基于软件 ...
- 学生成绩管理系统[C]
#include<stdio.h> #include<stdlib.h> #include<string.h> #include<conio.h> #d ...
- 同一个项目,项目名称不一致,这两个项目同时在Eclipse中出现
在Eclispse中,实际同一个项目,项目名称不一致,这两个项目同时在Eclipse中出现. ①打开项目文件夹,找到“.cproject”文件 ② 在<name>节点重命名 ③ 导入Ecl ...
- 在Salesforce中对Object实现Trigger的绑定
Trigger的相关属性详细解读请看如下链接: http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_triggers_c ...