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 /******************************************** ...
随机推荐
- JavaScript --经典问题
JavaScript中如何检测一个变量是一个String类型?请写出函数实现 方法1. function isString(obj){ return typeof(obj) === "str ...
- Pandas基础教程
pandas教程 更多地可以 参考教程 安装 pip install pandas pandas的类excel操作,超级方便: import pandas as pd dates = pd.date_ ...
- Nodejs Express笔记
Express做服务器,主要考虑到可能存在的高并发,js写起来也并不麻烦,环境搭建也异常简单.开车~ 由于主要目的就是用于生产环境,所以肯定不能用高版本的Nodejs,选LTS,没错的. 一.安装 这 ...
- 技本功丨知否知否,Redux源码竟如此意味深长(上集)
夫 子 说 元月二号欠下袋鼠云技术公号一篇关于Redux源码解读的文章,转眼月底,期间常被“债主”上门催债.由于年底项目工期比较紧,于是债务就这样被利滚利.但是好在这段时间有点闲暇,于是赶紧把这篇文章 ...
- 基础数据类型-list
序列是python中的基础数据结构,序列里每一个元素都有一个下标,从0开始,依次递增. list,tuple,dictionary是使用最频繁的三类数据结构. (1)序列都有的方法包括:索引,切片,检 ...
- Code obfuscatio (翻译!)
Description Kostya likes Codeforces contests very much. However, he is very disappointed that his so ...
- 20172330 2017-2018-1 《Java程序设计》第四周学习总结
20172330 2017-2018-1 <Java程序设计>第四周学习总结 教材学习内容总结 这一周的内容还是比较多的,而且很复杂,包含第四和第七章. 第四章向我们介绍了类结构的定义与概 ...
- mysql 相同表结构拷贝数据
第一种方法: 在导出表结构的时候可以勾选导出数据: 第二种方法: 表已经存在了,只需要数据即可.这个时候可以编写sql语句(暂不支持不同服务器之间的表数据复制) insert into tab_a(i ...
- C++ 学习笔记之 引用
一.定义: 引用就是某一变量(目标)的一个别名,对引用的操作与对变量直接操作完全一样. 二.用法: 基本用法 例如: int & a = b; 引用作为函数返回值 先看一个例子: #inclu ...
- 软工冲刺-Alpha 冲刺 (3/10)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 很胖,刚学,照猫画虎做了登录与注册界面. 展示GitHub ...