Posted: Sat Aug 14, 2004 2:21 pm
I think there is a \n after the last line
Regards
Javi
Regards
Javi
Code: Select all
The only part i'm not sure about it is the way the program may end executing (ive tried with while(cin) and While(!feof(stdin)) ).
Code: Select all
while (gets(x)) {
/* YOUR CODE */ ;
}
Code: Select all
cin.getline(x,128,'\n');
Code: Select all
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main()
{
string s;
char hej;
int i=0, k=0;
char maj[1000];
map<char, int> counter;
while(getline(cin,s))
{
for(int l=0; l<s.length();l++)
{
if(s[l]!=' ')
{
hej=s[l];
counter[hej]++;
}
}
for(map<char, int>::const_iterator memo = counter.begin(); memo!=counter.end(); memo++)
{
if(memo->second > k)
{
i=0;
k = memo -> second;
maj[i]= memo->first;
}
else if(memo->second == k)
{
i++;
maj[i]= memo->first;
}
}
for(int j=0; j<=i; j++)
{
cout<<maj[j];
}
cout<<" "<<k<<endl;
k=0;
counter.erase(counter.begin(), counter.end());
}
return 0;
}
Code: Select all
#include<stdio.h>
int main(){
char c;
int my[52]={0},i,max;
while(scanf("%c",&c)!=EOF){
if(c!='\n'){
if(c>=65 && c<=90){
my[c-65]++;
}
else if(c>=97 && c<=122){
my[c-97+26]++;
}
}
if(c=='\n'){
max=0;
for(i=0;i<26;i++){
if(my[i]>=my[i+26]){
my[i]+=my[i+26];
if(max<my[i]){
max=my[i];
}
my[i+26]=0;
}
else{
my[i+26]+=my[i];
if(max<my[i+26]){
max=my[i+26];
}
my[i]=0;
}
}
for(i=0;i<52;i++){
if(my[i]==max){
if(i<26){
printf("%c",i+65);
}
else{
printf("%c",i+97-26);
}
}
my[i]=0;
}
printf(" %d",max);
printf("\n");
} //newline;
} //while
return 0;
}
Code: Select all
for(i=0;i<26;i++){
if(my[i]>=my[i+26]){
my[i]+=my[i+26];
if(max<my[i]){
max=my[i];
}
my[i+26]=0;
}
else{
my[i+26]+=my[i];
if(max<my[i+26]){
max=my[i+26];
}
my[i]=0;
}
Code: Select all
max=0;
for(i=0;i<52;i++)
if(my[i]>max)
max=my[i];
Code: Select all
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.
Hello Howard.
(this is a blank line)
-------( - are spaces only)
~!@#$%^&*()_+{}:"<>?`1234567890-=[];',./
Code: Select all
e 6
al 7
a 3
Hlo 2
Hlo 2
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0
Did you consider this???If there are are several letters that have the highest frequency u should print all of them alphabetically.
Code: Select all
#include <iostream.h>
#include <ctype.h>
#include <string.h>
#include <stdio.h>
int main() {
int tamanho = 0;
int i = 0;
int aux1;
char aux2;
int j=0;
int maior=0;
char *linha = new char [4000];;
char letras[300];
int quantidade[300];
int indice=0;
strcpy(linha,"");
bool teste = false;
while (gets(linha)) {
for(i=0; i<300; i++) {
quantidade[i] = 0;
}
tamanho = strlen(linha);
indice = 0;
maior = 0;
for (i=0; i<tamanho; i++) {
teste = false;
for(j=0; j<indice; j++) {
if (linha[i] == letras[j]) {
quantidade[j]++;
teste = true;
}
}
if (!teste) {
if (isalpha(linha[i])!=0) {
letras[indice] = linha[i];
quantidade[indice] = 1;
indice++;
}
}
}
if (indice > 0) {
for(i=0; i<(indice-1); i++) {
for(j=(indice-1); j>1; j--) {
if (letras[j-1] > letras[j]) {
aux2 = letras[j-1];
aux1 = quantidade[j-1];
letras[j-1] = letras[j];
quantidade[j-1] = quantidade[j];
letras[j] = aux2;
quantidade[j] = aux1;
}
}
}
for(i=0; i<indice; i++) {
if (quantidade[i]>quantidade[maior]) {
maior = i;
}
}
maior = quantidade[maior];
for (i=0; i<indice; i++) {
if (quantidade[i] == maior) {
cout<<letras[i];
}
}
cout<<" "<<maior<<endl;
}
else {
cout<<"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz 0 "<<endl;
}
}
return 0;
}
Code: Select all
if(s[l]!=' ')
Code: Select all
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.
this, is, abso, lutely, crazy, dude.
Code: Select all
e 6
al 7
a 3
Hlo 2
, 5
Input:The list of letters should be an alphabetical list of upper case letters followed by an alphabetical list of lower case letters.
Code: Select all
bbaa
Code: Select all
ab 2
Code: Select all
ba 2
Code: Select all
#include<stdio.h>
int count[51];
void _initialize()
{
int i;
for(i=0;i<52;i++)
count[i]=0;
}
int main(void)
{
char ch,line[100];
int i,j,max=0;
while(1)
{
ch=getchar();
if(ch>=65 && ch<=90)
{
count[ch-65]++;
}
if(ch>=97 && ch<=122)
{
count[ch-71]++;
}
if(ch=='\n')
{
for(j=0;j<52;j++)
{
if(max<count[j])
max=count[j];
}
for(j=0;j<52;j++)
{
if(count[j]==max && j<=25)
{
printf("%c",j+65);
}
if(count[j]==max && j>25)
{
printf("%c",j+71);
}
}
printf(" %d\n",max);
max=0;
_initialize();
}
if(ch=='.')
{
for(j=0;j<52;j++)
{
if(max<count[j])
max=count[j];
}
for(j=0;j<52;j++)
{
if(count[j]==max && j<=25)
{
printf("%c",j+65);
}
if(count[j]==max && j>25)
{
printf("%c",j+71);
}
}
printf(" %d\n",max);
break;
}
}
return 0;
}
Code: Select all
#include<stdio.h>
int count[51];
void _initialize()
{
int i;
for(i=0;i<52;i++)
count[i]=0;
}
int main(void)
{
char ch,line[100];
int i,j,max=0;
while(1)
{
ch=getchar();
if(ch>=65 && ch<=90)
{
count[ch-65]++;
}
if(ch>=97 && ch<=122)
{
count[ch-71]++;
}
if(ch=='\n')
{
for(j=0;j<52;j++)
{
if(max<count[j])
max=count[j];
}
for(j=0;j<52;j++)
{
if(count[j]==max && j<=25)
{
printf("%c",j+65);
}
if(count[j]==max && j>25)
{
printf("%c",j+71);
}
}
printf(" %d\n",max);
max=0;
_initialize();
}
if(ch=='.')
{
for(j=0;j<52;j++)
{
if(max<count[j])
max=count[j];
}
for(j=0;j<52;j++)
{
if(count[j]==max && j<=25)
{
printf("%c",j+65);
}
if(count[j]==max && j>25)
{
printf("%c",j+71);
}
}
printf(" %d\n",max);
break;
}
}
return 0;
}