平常水题
来源:互联网 发布:mac怎么下载ps破解版 编辑:程序博客网 时间:2024/05/16 01:27
C - 怪文書 / Dubious Document
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.
He will receive a headline which contains one of the strings S1,…,Sn tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.
Find the longest string that can be created regardless of which string among S1,…,Sn the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
Constraints
1≤n≤50
1≤|Si|≤50 for every i=1,…,n.
Si consists of lowercase English letters (a - z) for every i=1,…,n.
Input
Input is given from Standard Input in the following format:
n
S1
…
Sn
Output
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line.
Sample Input 1
3
cbaa
daacc
Sample Input 2
3
a
aa
Time limit : 2sec / Memory limit : 256MB
Score : 300 points
Problem Statement
Snuke loves "paper cutting": he cuts out characters from a newspaper headline and rearranges them to form another string.
He will receive a headline which contains one of the strings S1,…,Sn tomorrow. He is excited and already thinking of what string he will create. Since he does not know the string on the headline yet, he is interested in strings that can be created regardless of which string the headline contains.
Find the longest string that can be created regardless of which string among S1,…,Sn the headline contains. If there are multiple such strings, find the lexicographically smallest one among them.
Constraints
1≤n≤50
1≤|Si|≤50 for every i=1,…,n.
Si consists of lowercase English letters (a - z) for every i=1,…,n.
Input
Input is given from Standard Input in the following format:
n
S1
…
Sn
Output
Print the lexicographically smallest string among the longest strings that satisfy the condition. If the answer is an empty string, print an empty line.
Sample Input 1
3
cbaa
daacc
acacac
aac
Sample Input 2
3
a
aa
b
Sample Output 2
The answer is an empty string.
(打比赛的时候没看懂题意,很尴尬......)
题意 :用n个字符串S1.......Sn 。每个字符串都由小写的a........z中的字母组成。找出每个字符串共有的字符并挑选最少的。如:样例: S1 :cbaa
S2 :daacc
S3 :acacac
三个字符串共有的字符是 a 和 c ,其中
S1 :有2个a S2 :有2个a S3 :有3个a 挑选最少的 -- aa
S1 : 有1个c S2 :有2个c S3 : 有3个c 挑选最少的 -- c
最后把挑选出来的字符按字典序最小排列 -- aac
解题思路:就直接扫一遍,每次就取最少的就行了(主要是考对字符串的处理)
#include<bits/stdc++.h>using namespace std;char h[1000][1000];//第一个方括号记录第i个字符串,第二个方括号记录第i个字符串的第j个字符。int s[1000],ans1[1000],ans2[1000];int main(){int n,flag = 0;scanf("%d",&n);for(int i = 1;i <= n;i++){scanf("%s",h[i]);//这里字符串的输入要注意一下s[i] = strlen(h[i]);}for(int i = 49;i <=74;i++){ans2[i] = 10000000;//初始化}for(int i = 1;i <= n;i++){for(int j = 0;j < s[i];j++){ ans1[h[i][j] - '0']++;}for(int k = 49;k <= 74;k++){ans2[k] = min(ans1[k],ans2[k]);}memset(ans1,0,sizeof(ans1));}char p;for(int i = 49;i <= 74;i++){if(ans2[i] != 0){for(int j = 1;j <= ans2[i];j++){flag = 1;printf("%c",i + '0');}}}if(flag == 0) printf("\n");}
0 0
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题
- 平常水题 Educational Codeforces Round 26 C (错误总结)
- 平常人要走平常路?
- 平常水题 — Codeforces Round #415 (Div. 2) B. Summer sell-off (贪心 + 错误总结)
- 50道java编程小题,平常可以拿来练手
- 50道java编程小题,平常可以拿来练手
- 平常整理
- 龙贝格积分
- LuCI架构原理(一)
- react环境搭建(基于dva)
- 启动Tomcat出现“Bad version number in .class file (unable to load class XXX)”解决
- django_auth.authenticate() 返回none
- 平常水题
- Android屏幕尺寸单位/屏幕适配
- Tar Jar War Ear
- 计算机编码基础
- 分离出十六进制数的某低几位
- 【Spring学习25】容器级启动和关闭回调
- 动态权限申请,android7.08.0权限特征
- 函数语法attributes,getAttribute(name),removeAttribute(name)
- c++设计模式之单例模式下的实例自动销毁(垃圾自动回收器)