Codeforces Round #329 (Div. 2)A 字符串处理
2 seconds
256 megabytes
standard input
standard output
Andrew often reads articles in his favorite magazine 2Char. The main feature of these articles is that each of them uses at most two distinct letters. Andrew decided to send an article to the magazine, but as he hasn't written any article, he just decided to take a random one from magazine 26Char. However, before sending it to the magazine 2Char, he needs to adapt the text to the format of the journal. To do so, he removes some words from the chosen article, in such a way that the remaining text can be written using no more than two distinct letters.
Since the payment depends from the number of non-space characters in the article, Andrew wants to keep the words with the maximum total length.
The first line of the input contains number n (1 ≤ n ≤ 100) — the number of words in the article chosen by Andrew. Following are n lines, each of them contains one word. All the words consist only of small English letters and their total length doesn't exceed 1000. The words are not guaranteed to be distinct, in this case you are allowed to use a word in the article as many times as it appears in the input.
Print a single integer — the maximum possible total length of words in Andrew's article.
4
abb
cacc
aaa
bbb
9
5
a
a
bcbcb
cdecdecdecdecdecde
aaaa
6
In the first sample the optimal way to choose words is {'abb', 'aaa', 'bbb'}.
In the second sample the word 'cdecdecdecdecdecde' consists of three distinct letters, and thus cannot be used in the article. The optimal answer is {'a', 'a', 'aaaa'}.
字符串处理的题目 体现代码能力之差
题意:输入n 个字符串 输出 最多只包含两种字符(拼凑成的整个字符串只有两种字符)的 所有字符串长度之和
处理:输入n个字符串 判断每个字符串种 字符的种类个数 如果 不大于3 则存下来 代码中用 jishu[][]数组存下相应字符的assii玛 mp数组记录出现次数
然后遍历所有字符组合 两个for循环 判断每行的两个字符 或1个字符是否与 当前组合相同 相同则 加到linshi (判断该行1个字符还是两个字符看代码 另外 注意处理 当前组合为同一字符的情况 避免重复) linshi 取最大值输出!
#include<bits/stdc++.h>
using namespace std;
int n;
char a[1000];
int mp[105][150];
int jishu[105][5];
int flag;
int main()
{
scanf("%d",&n);
memset(mp,0,sizeof(mp));
getchar();
for(int i=1; i<=n; i++)
{
memset(a,0,sizeof(a));
gets(a);
flag=0;
for(unsigned int j=0; j<strlen(a); j++)
{
if(mp[i][a[j]]==0)
{
jishu[i][flag]=a[j];
// cout<<jishu[i][flag]<<endl;
flag++;
}
mp[i][a[j]]++;
//cout<<mp[i][a[j]]<<endl;
if(flag>2)
{
memset(mp[i],0,sizeof(mp[i]));
memset(jishu[i],0,sizeof(jishu[i]));
break;
}
}
}
int re=0;
int linshi=0;
for(int j='a'; j<='z'; j++)
for(int k='a'; k<='z'; k++)
{
linshi=0;
for(int l=1; l<=n; l++)
{
if((jishu[l][0]==j&&jishu[l][1]==k)||(jishu[l][0]==k&&jishu[l][1]==j))
{
linshi+=(mp[l][j]+mp[l][k]);
//cout<<mp[l][j]<<" "<<mp[l][k]<<endl;
}
else
{
if(jishu[l][1]<97||jishu[l][1]>123)
{
if(jishu[l][0]==j)
{
linshi+=mp[l][j];
//cout<<linshi<<"*"<<endl;
} if(jishu[l][0]==k&&j!=k)
{
linshi+=mp[l][k];
//cout<<linshi<<"**"<<endl;
}
}
} }//cout<<j<<k<<linshi<<"**"<<endl;
re=max(re,linshi); }
//cout<<linshi<<endl;
cout<<re<<endl;
return 0;
}
Codeforces Round #329 (Div. 2)A 字符串处理的更多相关文章
- Codeforces Round #329 (Div. 2) B. Anton and Lines 逆序对
B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/pr ...
- Codeforces Round #329 (Div. 2) D. Happy Tree Party 树链剖分
D. Happy Tree Party Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/p ...
- Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:stand ...
- Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质
https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...
- Codeforces Round #329 (Div. 2)B. Anton and Lines 贪心
B. Anton and Lines The teacher gave Anton a large geometry homework, but he didn't do it (as usual ...
- Codeforces Round #329 (Div. 2) D. Happy Tree Party LCA/树链剖分
D. Happy Tree Party Bogdan has a birthday today and mom gave him a tree consisting of n vertecie ...
- Codeforces Round #329 (Div. 2) A. 2Char 暴力
A. 2Char Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/A De ...
- Codeforces Round #566 (Div. 2)C(字符串,SET)
#include<bits/stdc++.h>using namespace std;string s[100007];set<int>st[100007][7];int t[ ...
- Codeforces Round #329 (Div. 2)
推迟了15分钟开始,B卡住不会,最后弃疗,rating只涨一分... 水(暴力枚举) A - 2Char /******************************************** ...
随机推荐
- POJ 3256 (简单的DFS)
//题意是 K N, M; //有K个牛 N个牧场,M条路 ,有向的 //把K个牛放到任意的n个不同牧场中,问所有牛都可以到达的牧场数的总和 //这是一道简单的DFS题 //k 100 //n 1 ...
- 【xmlHttp_Class 远程访问类】使用说明
类名:xmlHttp_Class 说明:远程获取外部网站数据信息或执行一个外部网站程序 目录: 类型 名称 参数 返回 说明 属性 [必需] [xmlHttp].url = [urlString] - ...
- 【转】: 探索Lua5.2内部实现:虚拟机指令(2) MOVE & LOAD
name args desc OP_MOVE A B R(A) := R(B) OP_MOVE用来将寄存器B中的值拷贝到寄存器A中.由于Lua是register based vm,大部分的指令都是直接 ...
- ubuntu16.04图形界面安装中文输入法,中文展示
打开system Settings 设置 打开设置语言 安装Language Support 点击installed languages 选择chinese 打勾,安装 安装IBus框 ...
- POJ 1679 The Unique MST(最小生成树)
Description Given a connected undirected graph, tell if its minimum spanning tree is unique. Definit ...
- C++基础和STL,Effective C++笔记
这个作者总结的c++基础,特别好. 可以看看. http://blog.csdn.net/tham_/article/details/51169792
- 分页查询es时,返回的数据不是自己所期望的问题
在进行es分页查询时,一般都是用sql语句转成es查询字符串,在项目中遇到过不少次返回的数据不是自己所期望的那样时,多半原因是自己的sql拼接的有问题. 解决办法:务必要保证自己的sql语句拼接正确.
- LintCode-212.空格替换
空格替换 设计一种方法,将一个字符串中的所有空格替换成 %20 .你可以假设该字符串有足够的空间来加入新的字符,且你得到的是"真实的"字符长度. 你的程序还需要返回被替换后的字符串 ...
- OSG学习:使用已有回调示例
回调的类型有很多种,一般很容易就想到的是UpdateCallBack,或者EventCallBack,回调的意思就是说,你可以规定在某件事情发生时启动一个函数,这个函数可能做一些事情.这个函数就叫做回 ...
- Hadoop出现错误:WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable,解决方案
安装Hadoop的时候直接用的bin版本,根据教程安装好之后运行的时候发现出现了:WARN util.NativeCodeLoader: Unable to load native-hadoop li ...