A 2Char

原创 2015年11月17日 18:40:45

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




#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
#define maxn 1005
#define inf 0x3f3f3f3f
typedef long long LL;
char s[101][maxn];
int main()
{
	int n;
	freopen("in.txt", "r", stdin);
	while( ~scanf("%d", &n) ){
		int sum = 0;
		for(int i = 0; i < n; i++){
			scanf("%s", s[i]);
		}
		int res = 0;
		for(int i=0;i<26;i++)
			for(int j=i+1;j<26;j++){
				sum = 0;
				for(int k=0;k<n;k++){
					int t=0;
					while(s[k][t]){
						if(s[k][t] != i+'a' && s[k][t] != j+'a'){
							t=0;
							break;
						}
						t++;
					}	
					sum += t;	
				}
				res = max(sum, res);
			}
		printf("%d\n",res);
	}
}
		      	
				


版权声明:本文为博主原创文章,未经博主允许不得转载。

open flash char2 操作文当

  • 2014年11月14日 09:13
  • 852KB
  • 下载

C#程序设计基础教程与实训_8.char(2)

  • 2008年07月09日 13:50
  • 8.37MB
  • 下载

【1】ptr = malloc(0*sizeof(char))【2】关于typedef的用法总结【3】关于有符号数、无符号数和数据类型的总结

ptr = malloc(0*sizeof(char));(转载) 最近,看了有关malloc(0)的返回值以及其他一些问题的讨论,我把自己的感受和看法记录如下: 问题...

int2char函数

  • 2012年10月20日 09:06
  • 367B
  • 下载

oracle中char和varchar2数据类型的区别

Oracle中char和varchar2数据类型有什么区别?有数据”test”分别存放到char(10)和varchar2(10) 类型的字段中,其存储长度及类型有何区别? 首先解释一下: CH...

char和vchar2区别

  • 2009年04月13日 13:39
  • 1KB
  • 下载

CString2Char

  • 2014年01月23日 10:40
  • 316B
  • 下载

SQL中char varchar varchar2 的区别

char varchar varchar2 的区别  区别: 1.CHAR的长度是固定的,而VARCHAR2的长度是可以变化的, 比如,存储字符串“abc",对于CHAR (20),表示你存储的字符将...

char_step2

  • 2011年11月07日 22:53
  • 25KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:A 2Char
举报原因:
原因补充:

(最多只允许输入30个字)