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. Python 作用域和命名空间

    在介绍类之前,我首先要告诉你一些Python的作用域规则.类定义对命名空间有一些巧妙的技巧,你需要知道作用域和命名空间如何工作才能完全理解正在发生的事情.顺便说一下,关于这个主题的知识对任何高级Pyt ...

  2. lintcode12 带最小值操作的栈

    实现一个带有取最小值min方法的栈,min方法将返回当前栈中的最小值. 你实现的栈将支持push,pop 和 min 操作,所有操作要求都在O(1)时间内完成. 建一个栈helpStack,用来存放从 ...

  3. JAVA基础学习之路(八)[1]String类的基本特点

    String类的两种定义方式: 直接赋值 通过构造方法赋值 //直接赋值 public class test2 { public static void main(String args[]) { S ...

  4. java代码读取yarn聚合目录日志

    可以直接使用org.apache.hadoop.yarn.client.cli.LogsCLI(yarn logs -applicationId)中的main方法逻辑,如 public static ...

  5. C++clock()延时循环

    函数clock(),返回程序开始执行后所用的系统时间,但是有两个复制问题. 1.clock()返回时间的单位不一定是秒 2.该函数的返回类型在某些系统上可能是Long,也可能是unsigned lon ...

  6. MySQL Proxy使用

    使用MySQL将读写请求转接到主从Server. 一 安装MySQL Proxy MySQL Proxy的二进制版非常方便,下载解压缩后即用. 解压缩的目录为: $mysql-proxy_instal ...

  7. mysql下分组取关联表指定提示方法,类似于mssql中的cross apply

    转至:https://stackoverflow.com/questions/12113699/get-top-n-records-for-each-group-of-grouped-results ...

  8. Python高级编程-多进程

    要让Python程序实现多进程(multiprocessing),我们先了解操作系统的相关知识. Unix/Linux操作系统提供了一个fork()系统调用,它非常特殊.普通的函数调用,调用一次,返回 ...

  9. POJ 1873 The Fortified Forest(枚举+凸包)

    Description Once upon a time, in a faraway land, there lived a king. This king owned a small collect ...

  10. python中argparse库的使用教程链接

    这两篇文章详细介绍了argparse库的参数设置及使用包括位置参数与可选参数的用法 http://blog.csdn.net/guojuxia/article/details/44462381 htt ...