ZOJ 3603字符串操作
解题思路:找到公共子串然后升序输出
坑的地方就在于输入是存在相同字母的
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define MIN( x, y ) ( (x) < (y) ? (x) : (y) )
#define INF 0x7fffffff
#define KIND 26
#define MAXN 12
using namespace std; char str[MAXN];
int hash[KIND], ans[KIND]; int main(){
int cas, n, i, j;
scanf("%d", &cas);
while ( cas-- ){
scanf("%d", &n);
for( i = ; i < KIND; ++i )
ans[i] = INF;
for( i = ; i < n; ++i ){
scanf("%s", str);
memset( hash, , sizeof( hash ) );
for( j = ; j < MAXN; ++j )
hash[str[j]-'A']++;
for( j = ; j < KIND; ++j )
ans[j] = MIN( ans[j], hash[j] );
}
for( i = ; i < KIND; ++i )
while(ans[i]--)
printf("%c", i + 'A');
printf("\n");
}
return ;
}
Draw Something Cheat
Time Limit: 2 Seconds Memory Limit: 65536 KB
Have you played Draw Something? It's currently one of the hottest social drawing games on Apple iOS and Android Devices! In this game, you and your friend play in turn. You need to pick a word and draw a picture for this word. Then your friend will be asked what the word is, given the picture you have drawn. The following figure illustrates a typical scenario in guessing the word.

As you see, when guessing a word you will be given the picture and 12 letters. You must pick some of these letters to form a word that matches the picture. Each letter can only be used once. It is a lot of fun if your friend is a talented painter, but unfortunately some drawings from your friend are totally incomprehensible. After several times of becoming mad by the drawings, you find a way to cheat in the game.
In this game, letters not included in the correct answer are randomly generated. If you cannot find the correct answer when guessing, you can write down all the letters and restart the game. Then you would find some of these letters are changed. Of course these changed letters will never appear in the answer. By eliminating these letters you are a step closer to the answer.
So In this problem, you need to write a program to automate the cheating process. Given N strings of letters to the same picture, you need to eliminate as many letters as possible, and output the remaining letters.
Input
There are multiple test cases. The first line of the input is an integer T ≈ 1000 indicating the number of test cases.
Each test case begins with a positive integer N ≤ 20 indicating the number of times you have entered the game. Then N lines follow. Each line is a string of exactly 12 uppercase letters, indicating the candidate letters in one guess. It is guaranteed that the answer has at least 1 letter and has no more than 12 letters.
Output
For each test case, output the remaining letters in alphabet order after the process described above. One line for each test case.
Sample Input
2
2
ABCDEFGHIJKL
ABCDEFGHIJKL
2
SAWBCVUXDTPN
ZQTLFJYRCGAK
Sample Output
ABCDEFGHIJKL
ACT
ZOJ 3603字符串操作的更多相关文章
- D - D ZOJ - 1151 (字符串操作)
For each list of words, output a line with each word reversed without changing the order of the word ...
- python学习笔记(字符串操作、字典操作、三级菜单实例)
字符串操作 name = "alex" print(name.capitalize()) #首字母大写 name = "my name is alex" pri ...
- shell编程常用的截取字符串操作
1. 常用的字符串操作 1.1. 替换字符串:$ echo ${var/ /_}#支持正怎表达式 / /表示搜索到第一个替换,// /表示搜索到的结果全部替换. ...
- php字符串操作集锦
web操作, 主要就是对字符文本信息进行处理, 所以, 字符串操作几乎占了很大一部分的php操作.包括 注意strstr 和 strtr的区别? 前者表示字符串查找返回字符串,后者表示字符串中字符替换 ...
- java 字符串操作和日期操作
一.字符串操作 创建字符串 String s2 = new String("Hello World"); String s1 = "Hello World"; ...
- [No000078]Python3 字符串操作
#!/usr/bin/env python3 # -*- coding: utf-8 -*- '''Python 字符串操作 string替换.删除.截取.复制.连接.比较.查找.包含.大小写转换.分 ...
- Python 字符串操作及string模块使用
python的字符串操作通过2部分的方法函数基本上就可以解决所有的字符串操作需求: python的字符串属性函数 python的string模块 1.字符串属性方法操作: 1.>字符串格式输出对 ...
- C语言字符串操作总结大全
1)字符串操作 strcpy(p, p1) 复制字符串 函数原型strncpy(p, p1, n) 复制指定长度字符串 函数原型strcat(p, p1) 附加字符串 函数原型strn ...
- c# 字符串操作
一.字符串操作 //字符串转数组 string mystring="this is a string" char[] mychars=mystring.ToCharArray(); ...
随机推荐
- IOS中的自动布局
Autolayout是一种“自动布局”技术,专门用来布局UI界面 Autolayout能很轻松地解决屏幕适配问题 Autolayout的两条核心概念: >1 参照:通过参照其他控件或父控件来 ...
- eclipse主题插件
打开eclipse ,选择 Help 选择Install New Software 点击 Add 输入http://eclipse-color-theme.github.com/update,选中Ec ...
- CSS的clear属性
以下引用自w3school clear 属性定义了元素的哪边上不允许出现浮动元素.在 CSS1 和 CSS2 中,这是通过自动为清除元素(即设置了 clear 属性的元素)增加上外边距实现的.在 CS ...
- python成长之路13
一:SqlAlchemy ORM ORM:Object Relational Mapping 对象关系映射是一种程序技术,用于实现面向对象编程语言里不同类型系统的数据之间的转换 SQLAlchemy是 ...
- 2015-12-27 socket的用法
sk = socket.socket(socket.AF_INET,socket.SOCK_STREAM,0) sk.bind(address) s.bind(address) 将套接字绑定到地址.a ...
- hdu 2814 快速求欧拉函数
/** 大意: 求[a,b] 之间 phi(a) + phi(a+1)...+ phi(b): 思路: 快速求欧拉函数 **/ #include <iostream> #include & ...
- Spring 3 调度器示例 —— JDK 定时器和 Quartz 展示
Spring框架提供了执行和调度任务的抽象,支持线程池或者在应用服务器环境中代理给CommonJ. Spring也集成了支持使用JDK Timer和Quartz调度库提供的Quartz Schedul ...
- Android最新源码4.3下载-教程 2013-11
Android最新源码4.3下载-教程 有的下载会出现问题: 需要 修改manifest.xml中的fetch: "git://Android.git.linaro.org/" ...
- Service初步了解
1.Service什么 Service它是一个应用程序组件,Android其中的四个核心组件之间 Service没有图形界面 通过经常使用来处理一些比较长耗时的操作 可以使用Service更新Cont ...
- CSS的三种样式:内联式,嵌入式,外部式以及他们的优先级
从CSS 样式代码插入的形式来看基本能够分为下面3种:内联式.嵌入式和外部式三种. 1:内联式css样式表就是把css代码直接写在现有的HTML标签中,如以下代码: <p style=" ...