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. html简约风用户登录界面网页制作html5-css-jquary-学习模版

    2018--12-12 喜迎双十二,咳咳,,,,我不是打广告哈,购物的节日也不要忘记学习. 大家好,我又来了. 今天抽出来空把自己的学习心得给大家分享,这是一个可开发可扩展的用户登录界面,用于开发学习 ...

  2. 大理石在哪儿 (Where is the Marble?,UVa 10474)

    题目描述:算法竞赛入门经典例题5-1 #include <iostream> #include <algorithm> using namespace std; ; int m ...

  3. 在页面使用echarts的地图(解决地图不完整)

    测试环境:IDEA+Tomcat7 谷歌浏览器 创建好web工程,编写jsp页面,在自己编写的JSP页面上导包 现在echarts停止了在其网站上下载地图脚本,直接通过src引用网站上的china.j ...

  4. Python版本切换和Pip安装

    Python版本切换 现在常用的linux系统中都会默认携带python运行环境,在ubuntu 16.04 和centos 7.3中携带有Python 2.7 和Python3.5两个版本, 默认使 ...

  5. Python实现个性化推荐一

    现如今,网站用推荐系统为你提供个性化的体验,告诉你买啥,吃啥甚至你应该和谁交朋友.尽管每个人口味不同,但大体都适用这个套路.人们倾向于喜欢那些与自己喜欢的其他东西相似的东西,也倾向于与自己身边的人有相 ...

  6. Python3 Tkinter-OptionMenu

    1.创建 from tkinter import * root=Tk() v=StringVar() v.set('xs') om=OptionMenu(root,v,'Python','PHP',' ...

  7. Thunder团队第二周 - Scrum会议2

    Scrum会议2 小组名称:Thunder 项目名称:爱阅app Scrum Master:胡佑蓉 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...

  8. 201621044079 韩烨 week11-作业11-多线程

    作业11-多线程 参考资料 多线程参考文件 1. 本周学习总结 1.1 以你喜欢的方式(思维导图或其他)归纳总结多线程相关内容. 2. 书面作业 本次PTA作业题集多线程 1. 源代码阅读:多线程程序 ...

  9. DOS工具

    winver  检查Windows版本wmimgmt.msc  打开windows管理体系结构wupdmgr  windows更新程序wscript  windows脚本宿主设置write  写字板w ...

  10. Cacti自定义脚本,监测Docker信息(Script/Command方式)

    一 环境背景 监控主机A:192.168.24.231:被监控主机B:192.168.24.233 A/B主机,通过公私钥建立ssh连接 [操作B主机时不需要输入密码,详见笔记:http://app. ...