Posted: Thu Oct 12, 2006 2:47 pm
if u print a blank line u will get PE. u dont need 2 print anything if there is no lower/uppercase letter in the input.[/quote]
Code: Select all
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define SQ(x) (x)*(x)
string solve( string s ) {
int cnt[52]; memset( cnt, 0, sizeof( cnt ) );
for( int i = 0; i < s.size(); ++i ) {
if( s[i] >= 'a' && s[i] <= 'z' ) cnt[ s[i] - 'a' + 26 ]++;
if( s[i] >= 'A' && s[i] <= 'Z' ) cnt[ s[i] - 'A' ]++;
}
int x = *(max_element( cnt, cnt + 52 ) );
if( !x ) return "";
string ret = "";
for( int i = 0; i < 26; ++i ) if( cnt[i] == x ) ret += (i + 'A');
for( int i = 26; i < 52; ++i ) if( cnt[i] == x ) ret += (i + 'a' - 26);
ret += " "; ret += ( x + '0' );
return ret;
}
int main() {
string s;
while( getline( cin, s ) ) {
string o = solve( s );
if( o.size() ) cout << o << endl;
}
return 0;
}
Code: Select all
REMOVED
Code: Select all
# include<stdio.h>
int main()
{
char ar[52]={'A','a','B','b','C','c','D','d','E','e','F','f','G','g',
'H','h','I','i','J','j','K','k','L','l','M','m',
'N','n','O','o','P','p','Q','q','R','r','S','s','T','t',
'U','u','V','v','W','w','X','x','Y','y','Z','z'};
int count[52];
char ch;
int i;
int max;
char c;
while(ch=getchar())
{
for(i=0;i<52;i++)
{
count[i]=0;
}
while(ch!='\n')
{
for(i=0;i<52;i++){
if(ch==ar[i])
count[i]=count[i]+1;
}
ch=getchar();
}
max=0;
for(i=0;i<52;i++)
{
if(max<count[i])
{
max=count[i];
c=ar[i];
}
}
for(i=0;i<52;i++)
{
if(count[i]==max)
printf("%c",ar[i]);
}
printf(" %d\n",max);
}
return 0;
}
Code: Select all
#include <stdio.h>
int main()
{
char c;
int count;
int Is_Alph(char c);
freopen("in.txt", "r", stdin);
while((c=getchar())!=EOF)
{
count=0;
while (c=='\n')
{
c=getchar();
}
while (c!='\n'&&c!=EOF)
{
if (Is_Alph(c))
{
count++;
}
while((c=getchar())&&Is_Alph(c)&&c!='\n'&&c!=EOF);
if (c=='\n')
{
break;
}
while((c=getchar())&&(!Is_Alph(c))&&c!='\n'&&c!=EOF);
}
printf("%d\n", count);
if (c==EOF)
{
return 0;
}
}
return 0;
}
int Is_Alph(char c)
{
if (c>='A'&&c<='Z'||c>='a'&&c<='z')
{
return 1;
}
else
{
return 0;
}
}
Code: Select all
#include <stdio.h>
#include <math.h>
#include <string>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
int main() {
char ch;
int major;
int reads;
map<char, int> chs;
chs.clear();
major = 0;
reads = 0;
while ( (ch = fgetc(stdin)) != EOF ) {
if (ch == '\n') {
if (major > 0) {
map<char,int>::iterator it = chs.begin();
for (;it != chs.end(); it++) {
if (it->second == major)
printf("%c", it->first);
}
printf(" %d\n", major);
} else if (major == 0) {
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0\n");
}
chs.clear();
major = 0;
reads = -1;
} else if (isalpha(ch) == true) {
map<char,int>::iterator it = chs.find(ch);
if (it == chs.end()) {
chs[ch] = 1;
if ( 1 > major ) major = 1;
} else {
it->second = it->second + 1;
if ( it->second > major ) major = it->second;
}
}
reads++;
}
if (reads > 0) {
if (major > 0) {
map<char,int>::iterator it = chs.begin();
for (;it != chs.end(); it++) {
if (it->second == major)
printf("%c", it->first);
}
printf(" %d\n", major);
} else if (major == 0) {
printf("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0\n");
}
}
return 0;
}
Code: Select all
#include <stdio.h>
main()
{
int i;
char *suffix[]= { "st", "nd", "rd" };
char *item[]= { "Unix" , "cat", "sed", "awk", "grep", "ed", "vi"};
printf("In the beginning, there was nothing.\n");
for (i= 0; i < 7; i++)
printf("And on the %d%s day, God created %s. And it was good.\n",
i + 1, (i < 3) ? suffix[i] : "th", item[i]);
}
But then God saw that vi led people into temptation. Instead of choosing the righteous ways of make, dbx, and RCS, people used long command lines, printf(), and tape backups.
So God decreed, ``I see that Engineers have thus defiled my vi. And so, I shall create emacs, an editor more powerful than words. Further, for each instantiation vi hitherto, the Engineer responsible shalt perform Penance. And lo, the Penance wilt be painful; there will be much wailing and gnushingof teeth. The Engineer will read many lines of text. For each line of text, the Engineer must tell me which letters occur the most frequently.''
``I charge you all with My Golden Rule: 'Friends shalt not let friends use vi'.''
Input and Output
Each line of output should contain a list of letters that all occured with the highest frequency in the corresponding input line, followed by the frequency.
The list of letters should be an alphabetical list of upper case letters followed by an alphabetical list of lower case letters.
Sample Input
When riding your bicycle backwards down a one-way street, if the
wheel falls of a canoe, how many ball bearings does it take to fill
up a water buffalo?
Hello Howard.
Code: Select all
di 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
aimn 1
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
i 2
dfrs 2
e 4
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
n 8
i 3
d 7
i 6
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 14
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 55
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 7
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
tu 3
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 15
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 15
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
p 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
e 6
al 7
a 3
Hlo 2
Code: Select all
#include <iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
char str[500];
int arr[52];
int index,k,j;
// freopen("input.txt","r",stdin);
//freopen("output.txt","w",stdout);
while(gets(str))
{
int length = strlen(str);
if(length==0) continue;
for(k=0;k<=52;k++) arr[k]=0;
for(j=0;j<length;j++)
{
char ch =str[j];
if(ch>=65 && ch <=90)
{
index =ch-65+26;
arr[index]+=1;
}
if(ch>=97 && ch<=122)
{
index = ch-97;
arr[index]++;
}
}
int mi=0;
int i;
char c;
for(i=0;i<52;i++)
{
if(arr[mi] < arr[i])
{
mi=i;
}
}
for(i=26;i<52;i++)
if(arr[mi]==arr[i])
{
c=65+i-26;
printf("%c",c);
}
for(i=0;i<26;i++)
if(arr[mi]==arr[i])
{
c=97+i;
printf("%c",c);
}
printf(" %d\n",arr[mi]);
}
return 0;
}