A. 2Char
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

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.

Output

Print a single integer — the maximum possible total length of words in Andrew's article.

Sample test(s)
Input
4
abb
cacc
aaa
bbb
Output
9
Input
5
a
a
bcbcb
cdecdecdecdecdecde
aaaa
Output
6
Note

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 字符串处理的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. Codeforces Round #541 (Div. 2) E 字符串 + 思维 + 猜性质

    https://codeforces.com/contest/1131/problem/D 题意 给你n个字符串,字符串长度总和加起来不会超过1e5,定义字符串相乘为\(s*s1=s1+s[0]+s1 ...

  5. 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 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #566 (Div. 2)C(字符串,SET)

    #include<bits/stdc++.h>using namespace std;string s[100007];set<int>st[100007][7];int t[ ...

  9. Codeforces Round #329 (Div. 2)

    推迟了15分钟开始,B卡住不会,最后弃疗,rating只涨一分...   水(暴力枚举) A - 2Char /******************************************** ...

随机推荐

  1. 在deepin系统中制作桌面快捷方式

    在使用deepin-wine 安装一些软件的时候,每次启动都需要到.deepinwine目录下运行deepin-wine xx.exe.笔者在安装过HeidiSql之后,一直苦于这种情况.比较好的解决 ...

  2. Python全栈 MongoDB 数据库(Mongo、 正则基础、一篇通)

                  终端命令:       在线安装:         sudo apt-get install mongodb         默认安装路径 :  /var/lib/mong ...

  3. vue.js 创建组件 子父通信 父子通信 非父子通信

    1.创建组件 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  4. java利用POI实现读取Word并获取指定样式的文本

    import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.model.StyleDescription; import o ...

  5. CSS3制作各种形状图像(转)

    CSS3制作各种形状图像 浏览:1417 | 更新:2015-05-24 14:43 | 标签:css 1 2 3 4 5 6 7 分步阅读 圆形-椭圆形-三角形-倒三角形=左三角形-右三角形-菱形- ...

  6. Android 网络编程 API笔记 - java.net 包 权限 地址 套接字 相关类 简介

    Android 网络编程相关的包 : 9 包, 20 接口, 103 类, 6 枚举, 14异常; -- Java包 : java.net 包 (6接口, 34类, 2枚举, 12异常); -- An ...

  7. 福州大学软工1816 | K班 第一次作业

    (一)回想一下你初入大学时对计算机专业的畅想 (1)当初你是如何做出选择计算机专业的决定的? 本身对于计算机感兴趣.高考完之后翻了书,对于物理数学等基础学科兴趣不大,对金融等商科几乎毫无了解,再加上当 ...

  8. freefcw/hustoj Install Guide

    First of all, this version hustoj is a skin and improved for https://code.google.com/p/hustoj/. So t ...

  9. 华为oj----iNOC产品部-杨辉三角的变形 .

    此题提供三种方法,第一种,一开始就能想到的,设置一个足够大的数组存储生成的杨辉三角,然后进行判断就行,此方法参见:华为oj iNOC产品部-杨辉三角的变形 另一种方法是采用递归: 三角形的每行的个数为 ...

  10. OSG学习:转动的小汽车示例

    由于只是简单的示例,所以小汽车的模型也比较简单,是由简单的几何体组成. 代码如下: #include <osg\ShapeDrawable> #include <osg\Animat ...