Page 2 of 4

Posted: Sun Jun 29, 2003 8:39 am
by Hisoka
hello r.z.

I think you must use scanf("\n"); instead of fflush(stdin); because maybe fflush(stdin) doesn't work in judge compiler. :o I'm not sure too about this, but I always do that.

GOOD LUCK...

Posted: Sun Jun 29, 2003 12:04 pm
by r.z.
what?
what should I change?

Posted: Sun Jun 29, 2003 12:06 pm
by r.z.
Oh I figured it out
thanks :wink:

help about 10008

Posted: Sun Mar 07, 2004 12:28 pm
by Salmin Sultana
why wa?

#include<stdio.h>
#include<ctype.h>
#include<string.h>

struct freq{
char c;
unsigned long int f;

};
struct freq letter[26];

unsigned long int i,n,l,j;
int index;
char str[150000000];

int main(){

scanf("%lu",&n);
for(;n>0;n--){

fflush(stdin);
gets(str);
l=strlen(str);
for(i=0;i<l;i++) {
if(isalpha(str))
{
index=(toupper(str))-'A';
letter[index].c=toupper(str);
letter[index].f++;
}
}
}
struct freq temp;
for(i=0;i<25;i++){
for(j=i+1;j<26;j++) {
if(letter.f<letter[j].f){
temp=letter;
letter=letter[j];
letter[j]=temp;
}
else if(letter.f==letter[j].f){
if(letter.c>letter[j].c){
temp=letter;
letter=letter[j];
letter[j]=temp;
}

}
}
}

for(i=0;i<26;i++)
{ if(letter[i].f!=0) {
printf("%c ",letter[i].c);
printf("%d\n",letter[i].f);
}
}
return 0;
}

same problem

Posted: Sun Mar 07, 2004 2:07 pm
by sohel
hi again,

using fflush is a little risky! :-?

avoid using it and implement scanf("%d\n", &n) when you want to clear the input buffer.

Again I made the modification and got AC.

Hope it helps.
:wink:

sohel

Posted: Tue Mar 09, 2004 7:23 pm
by osan
it's simply a nice way that u teach someone.:))
you should realize the person is a new comer & everyone isn't much intelligent like u.:))

10008

Posted: Wed Jul 14, 2004 11:57 am
by oulongbin
why i always got compile error??
[cpp]
#include <iostream>
using namespace std;
#include <cstring>
int main()
{
int n,count[26];
int caf[26];
for(int k=0;k<26;k++)
{
count[k]=0;
caf[k]=k;
}
cin>>n;
cin.get();

while(n--)
{
int len,i;
char a[1000];
cin.getline(a,1000);
len=strlen(a);
strupr(a);
for(i=0;i<len;i++)
{
switch(a)
{
case 'A':count[0]++;break;
case 'B':count[1]++;break;
case 'C':count[2]++;break;
case 'D':count[3]++;break;
case 'E':count[4]++;break;
case 'F':count[5]++;break;
case 'G':count[6]++;break;
case 'H':count[7]++;break;
case 'I':count[8]++;break;
case 'J':count[9]++;break;
case 'K':count[10]++;break;
case 'L':count[11]++;break;
case 'M':count[12]++;break;
case 'N':count[13]++;break;
case 'O':count[14]++;break;
case 'P':count[15]++;break;
case 'Q':count[16]++;break;
case 'R':count[17]++;break;
case 'S':count[18]++;break;
case 'T':count[19]++;break;
case 'U':count[20]++;break;
case 'V':count[21]++;break;
case 'W':count[22]++;break;
case 'X':count[23]++;break;
case 'Y':count[24]++;break;
case 'Z':count[25]++;break;
}
}
}
for(int i=0;i<25;i++)
{
for(int j=0;j<25-i;j++)
if(count[j]<count[j+1])
{
int t;
t=count[j];
count[j]=count[j+1];
count[j+1]=t;
t=caf[j];
caf[j]=caf[j+1];
caf[j+1]=t;
}
}
for(int i=0;i<25;i++)
{
if(count!=0)
cout<<char(caf+65)<<" "<<count<<endl;
}


return 0;
}
[/cpp]

oops

Posted: Wed Jul 14, 2004 3:32 pm
by sohel
You are not allowed to use the function strupr()..

... it is not defined in ANSI C.

Posted: Thu Jul 15, 2004 8:20 am
by oulongbin
thank you very much.
now i got AC.

10008 - What's Cryptanalysis? - NEED INPUTS/OUTPUTS

Posted: Sat Apr 23, 2005 9:02 am
by Jemerson
My program seems to work perfectly, but the judge insists on WA, could any of you guys post some samples of Inputs and their respective Outputs? And Id also like to know your buffer size =]

Just to show my program behavior, here are some inputs and outputs generated by it over 3 different executions:

Execution #1:

1
my name is jemerson
E 3
M 3
N 2
S 2
A 1
I 1
J 1
O 1
R 1
Y 1 (Ends here, no '/n')

Execution #2:

5
jjjjj jajalkdsfka
jallf;f j j j j jj
141lk; 1 . 1..11..1 klasjf
jjklkuapuoivuypozyozopibyzopybzopybq
hhfhfhfhf
J 17
F 8
A 6
K 6
L 6
O 6
H 5
P 5
Y 5
Z 4
B 3
U 3
I 2
S 2
D 1
Q 1
V 1 (Ends here, no '/n')

Execution #3:

9
fkaljs;lkjlk;voizuyoiuzpy yziu oiblkz;lk jzjlkjl;kj 1?!?!?!? ?
afshfkjahkjl hiuy ayufoyaiuyfiouayiufyoiu kjhkjh klah,mrhq,m n.a,m nz/vzv28497109817 940871 40198lhakjhf
jahfkj hmzhvm,nzv.kzjvhlkzjviuzyvz
a fakf
ahkjhfiuayi uqr./qmrq 'k ., nm m .,m ./m ., m ,.
jaklfjlkaufp aiouzpov iuzvoiuvz
oqiurqlkjrq.m1lkj41 41749801741i lkaf,.vmz fv afaf
afjalkjflkaufoiapufz l;jvz.,mv z.m,v z .mz /m.,zv
m lkjlkj
K 28
J 25
A 24
Z 23
F 21
L 21
U 19
I 18
M 18
V 17
H 15
O 11
Y 11
Q 7
R 5
N 4
P 4
S 2
B 1 (Ends here, no '/n')


Thanx in advance

Re: 10008 - What's Cryptanalysis? - NEED INPUTS/OUTPUTS

Posted: Sat Apr 23, 2005 10:16 pm
by tan_Yui
Hi, Jemerson. I checked your sample input, and it was same as my code output. But my code prints '\n' at the end of every line.
My code deals with integer size buffer to count the words.

And, I prepared 2 set of input. Please check :)
( Of course, the word "[EOF]" isn't contained as i/o text )

Case 1 :

Code: Select all

12
yich liny Uf Uutput cUntiinK i Kingly uppyrciKy lyttyr, x
fUllUwyd by i Kingly Kpicy, thyn fUllUwyd by i pUKitivy dycimil intygyr. 
Thy intygyr indicityK hUw miny timyK thy cUrryKpUnding lyttyr ippyirK in thy input tyxt. 
Uppyr ind lUwyr ciKy lyttyrK in thy input iry tU by cUnKidyryd thy Kimy. 
NU Uthyr chirictyrK muKt by cUuntyd. q
Thy Uutput muKt by KUrtyd in dyKcynding cUunt Urdyr; thit iK, 
thy mUKt fryquynt lyttyr iK Un thy firKt Uutput liny, 
ind thy liKt liny Uf Uutput indicityK thy lyiKt fryquynt lyttyr. vVvV
If twU lyttyrK hivy thy Kimy fryquyncy, 
thyn thy lyttyr which cUmyK firKt in thy ilphibyt muKt ippyir firKt in thy Uutput. 
If i lyttyr dUyK nUt ippyir in thy tyxt, 
xXthyn thit lyttyr muKt nUt ippyir in thy Uutput. xQQ 
[EOF]
Case 2 :

Code: Select all

3
= 1 + 2 = 2 + 1 = -9 + 12
= 18 * ( 1 / 6 ) = -3 * -1
= 16^(1 / 2) - 1 = ???.......
[EOF]
Output is here :
Case 1 :

Code: Select all

Y 97
T 88
I 71
U 58
N 40
K 34
R 34
H 29
P 24
L 23
C 18
D 16
F 12
M 11
B 6
G 6
Q 6
V 6
W 6
X 6
[EOF]
Case 2 :

Code: Select all

[EOF]
Best regards.

Posted: Sat Apr 23, 2005 11:20 pm
by Jemerson
Man, thanx for your help, i got the same answer of yours, also tested a few worse cases but still got WA, dont know what to do.. im pissed =[

Posted: Mon Apr 25, 2005 1:41 am
by tan_Yui
Jemerson wrote:i got the same answer of yours, also tested a few worse cases but still got WA, dont know what to do..
Oh...
This problem_10008 is not so complex that I think
your code have some careless misses.
If your code of output part is correct, your code may have bugs at input part.
The next n lines will contain zero or more characters
Try check again for above description.
If this is not the source of the trouble, I can't guess any more... sorry.

Paste your code in this board may be a one of solution.

Input :

Code: Select all

6
x
x
x
x
Below line is a blank line.  This is checking for input itself.

If your input part was wrong, it may read this line .... thanks.
Right Output :

Code: Select all

I 8
E 5
L 5
N 5
S 4
X 4
T 3
A 2
B 2
C 2
F 2
H 2
K 2
O 2
G 1
P 1
R 1
U 1
W 1
Bad Output :

Code: Select all

I 13
N 9
T 8
A 7
E 7
S 7
L 6
R 5
H 4
O 4
X 4
F 3
K 3
P 3
U 3
W 3
B 2
C 2
G 2
Y 2
D 1
M 1
Best regards.

Posted: Mon May 09, 2005 9:19 pm
by Jemerson
Guys, my code was too ugly, i was computing impossible cases and it was confusing me and the program by itself, i cleaned it up and got the acceptance. Thanx a lot for your help

10008

Posted: Fri Sep 02, 2005 6:31 am
by jesin_21

Code: Select all

int main()
{

	int n;

	long long int s[27];
	char c;
	int i,j;
	
	while(cin>>n)
	{
	      i=0; j=0;
	      for(j=0;j<27;j++)
	      s[j]=0;
	      while(i<n)
	      {
		c=getchar();

		if(c=='\n')
		i++;

		else
		{

		  if(c>='A'&&c<='Z')
		  {
		    j = c - 65;
		    s[j] = s[j] + 1;
		  }
		  if(c>='a'&& c<='z')
		  {
		    j = c - 97;
		    s[j] = s[j] + 1;
		  }
		}
	      }
	    
	      int max,k,temp;
	      char ch;
	      for(j=0;j<26;j++)
	      {
		 max =0;
		 for(k=0;k<26;k++)
		 {
			if(s[k]>max)
			{
			    max = s[k];
			    temp = k;
			}
		 }
		 ch = temp + 'A';
		 s[temp]=0;
		 if(max!=0)
		 cout<<ch<<" "<<max<<"\n";
	      }
	}
return 0;
}[quote]i get wrong answer every time i submit it.sumbody please help me with sample input output or justs tell me wat is wrong with my code[/quote]