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 ...
随机推荐
- 开发一款完备的android应用所必备的知识
原文:http://blog.csdn.net/xyz_lmn/article/details/17575709
- DOM – (w3school)1.DOM 方法 + 2.DOM属性 + 3.DOM 元素
1.DOM 方法 一些 DOM 对象方法 这里提供一些您将在本教程中学到的常用方法: 方法 描述 getElementById() 返回带有指定 ID 的元素. getElementsByTa ...
- n的阶乘高精度算法【阶乘】
C语言实验——求阶乘(循环结构) Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 题目链接:http://acm.sdut.edu ...
- AngularJS讲义-控制器
在Angular中,控制器(Controller)就是基于JavaScript的构造方法,主要用来构造模型并建立模型和视图之间的数据绑定.控制器里面定义了应用程序的逻辑和行为. 通过ng-contro ...
- C# 文件读取方法,自己写的例子,保存一下,备用
/// <summary> /// 将output.config内容传到app.config /// </summary> string ReadString; //两个地址 ...
- 物化视图刷新慢--有可能是mv log被多个mv使用造成的
同事说物化视图刷新慢,经检生产环境,发现部分物化视图刷新慢的原因是:由于同一个物化视图日志(mv log)被多个物化视图(mv)使用,不同的物化视图(mv)使用不同的刷新间隔,导致物化视图日志(mv ...
- 湖南省第十二届大学生计算机程序设计竞赛 B 有向无环图 拓扑DP
1804: 有向无环图 Time Limit: 5 Sec Memory Limit: 128 MBSubmit: 187 Solved: 80[Submit][Status][Web Board ...
- ios本地推送
#import "AppDelegate.h" @interface AppDelegate () @end @implementation AppDelegate //无论程序在 ...
- Linux内核system_call中断处理过程
“平安的祝福 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 ” men ...
- Popupwindow 的简单实用,(显示在控件下方)
第一步: private PopupWindow mPopupWindow; 第二步:写一个popupwindow的布局文件XML <?xml version="1.0" e ...