Page 3 of 4

Posted: Fri Sep 02, 2005 8:17 pm
by sidky
while debugging your code, i was faced with two problems.

first, your program was having problem taking input as you have used both cin and getchar simultaneously. this might be a bug of visual c++. i dont know whether judge machine behaves the same or not.

secondly, you overlooked that there is a trailing '\n' after the line numbers. when you scan the line number (cin >> n) you scan the number, but the '\n' remains in the input. so, when you start reading the texts, the first thing it finds is that '\n'. so, it treats the first line as an empty line, but that is not a part of the text.

i changed the cin to scanf and scanned that trailing '\n', and that was enough to get your program acc

10008 What's Cryptanalysis , Why WA???

Posted: Thu Jan 26, 2006 5:44 pm
by ashikzinnatkhan
My code is:

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


int letter[26][2] , temp0 , temp1 ;


void main()
{
char ch ;
long i , j , newline = 0 , totalnum = 0 , finished = 0 ;

scanf("%ld", &totalnum);
fflush(stdin);

newline = 0;
finished = 0;

for(i=0 ; i<26 ; i++)
{
letter[0] = i+65 ;
letter[1] = 0 ;
}


while( finished == 0 )
{
ch = getchar();

if(ch == '\n' ) newline++;

if(newline >= totalnum) finished = 1;

i = toupper(ch);
i = i - 65;

if( i>=0 && i<=25) letter[1]++ ;

if(finished == 1)
{

for( i=1; i<26 ; ++i)
for(j=25; j>=i; --j)
{
if(letter[j-1][1] < letter[j][1] )
{
temp0 = letter[j-1][0];
temp1 = letter[j-1][1];

letter[j-1][0] = letter[j][0];
letter[j-1][1] = letter[j][1];

letter[j][0] = temp0;
letter[j][1] = temp1;

}

}


for( i=0; i<26; i++)
{
if(letter[1] > 0) printf("%c %d\n",letter[0] , letter[1] );

}

fflush(stdin);

}


}

}





It's seems to me ok. But giving WA each time I submit.
Can anyone tell me what's wrong with my code or what is wrong
with my logic?
Please help.

Re: 10008 What's Cryptanalysis , Why WA???

Posted: Sun Jan 29, 2006 2:25 pm
by tan_Yui
First of all, try the sample input to find the correct output.
You code was failed. :(

After you changed the code, if still get the wrong answer, post on this thread again.

Thank you.

10008 Compile Error

Posted: Thu Feb 16, 2006 1:16 am
by Lotendil
Ok, I am AC boy!!!

Posted: Thu Feb 16, 2006 6:12 am
by chunyi81
You need to #include <cctype> to use functions such as isalpha

And remove this code after you get AC.

ashik's code is allright in my machine

Posted: Wed May 03, 2006 6:55 pm
by eyeabhi
ashik,
i also got a WA in 10008. my program also seems to be correct and is give exactly the sample output for sample input. I think we both having a critical problem--- our code does not give proper output on some other machines...
please someone tell us what to do?

ashik's code is allright in my machine

Posted: Wed May 03, 2006 6:56 pm
by eyeabhi
ashik,
i also got a WA in 10008. my program also seems to be correct and is give exactly the sample output for sample input. I think we both having a critical problem--- our code does not give proper output on some other machines...
please someone tell us what to do?

Abhishek
Dhaka

Re: ashik's code is allright in my machine

Posted: Wed May 03, 2006 7:48 pm
by mamun
eyeabhi wrote:our code does not give proper output on some other machines...
some other machines, interesting! Problem with ashik's code is probably parsing the input. If you still have problem then post your code with code tags.

Here's my code.. it gets WA each time

Posted: Wed May 03, 2006 8:20 pm
by eyeabhi
please check this out and give a response....
Thank u very much..[/code]

Posted: Thu May 04, 2006 6:37 am
by mamun
Both of you've done almost the same thing for input. Instead of flushing the input buffer just write
scanf("%d\n", &lines);

Thank u GURU

Posted: Thu May 04, 2006 9:04 am
by eyeabhi
using scanf("%d\n"), i got acc.
my idea about "some other machines" was completely wrong.
Thank u very much.

Posted: Sat Sep 15, 2007 6:44 pm
by Fuad Hassan EWU
Hi, i don't why but this code is giving me Compile error. why?????????????

Code: Select all

#include<cstdio>
#include<iostream>
#include<string>
#include<cctype>
#include<algorithm>
#include<cstdlib>

using namespace std;

struct crypt
{
	char ltr;
	int freq;
}x[10000];

bool comp(crypt A,crypt B)
{
	if(A.freq>B.freq)
		return true;
	else if(A.freq==B.freq)
		return A.ltr<B.ltr;
	return false;
}

int cmp_func(const void *a,const void *b)
{
	return (strcmp((char *)a,(char *)b));
}


char str[10000];

int main()
{
	
   	
	char ch;
	int i,k,m,j,n;

	cin>>n;
	
		k=0;
		i=0;
		while(i<=n)
		{
			scanf("%c",&ch);
			if(ch=='\n')
				i++;
			else
			{
				if((ch>='a'&& ch<='z')||(ch>='A'&& ch<='Z'))
				{
					str[k]=toupper(ch);
					k++;
				}
			}
		}


		str[k]='\0';
		qsort(str,strlen(str),sizeof(str[0]),cmp_func);

		m=0;j=1;
		for(i=0;i<k;i++)
		{
			if(str[i]!=str[i+1])
			{
				x[m].ltr=str[i];
				x[m].freq=j;
				j=1;
				m++;
			}
			else j++;
		}

		sort(x,x+m,comp);

		for(i=0;i<m;i++)
		{
			cout<<x[i].ltr<<' '<<x[i].freq<<endl;
		}
	
	
	return 0;
}

Re: 10008 - What's Cryptanalysis?

Posted: Mon May 26, 2008 7:43 pm
by sreejond
What the problem with my code.Plz help me i facing lot of time WA.
thank you, i'll wait for your replies.

here is my code:

Code: Select all

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

char text[10000],ch;
long count[130];

int main()
{
	long t,i,f,ii,j,min,len,letter,k;

	scanf("%ld%c",&t,&ch);
	for(i=0;i<t;i++)
	{
		
		gets(text);		
		len=strlen(text);
		for(ii=0;ii<len;ii++)
		{
			if((text[ii]>=65 && text[ii]<=90) || (text[ii]>=97 && text[ii]<=122))
			{
				if(text[ii]>=97 && text[ii]<=122)
				{
					count[text[ii]-32]++;
					continue;
				}
				count[text[ii]]++;
			}
		}
	}

	f=0;
	for(k=1;k<=26;k++)
	{
		min=0;
		for(j=65;j<=90;j++)
		{
			if(count[j]>min)
			{
				min=count[j];
				letter=j;
			}
		}
		if(min==0)
			continue;
		if(f==1 && min>0)
		{
			printf("\n");
		}
		f=1;
		count[letter]=-1;
		printf("%c %ld",letter,min);
	}

	return 0;
}
[Edited by Jan : Use code tags]

Re: 10008 - What's Cryptanalysis?

Posted: Mon May 26, 2008 8:20 pm
by Jan
Suppose the input is

Input:

Code: Select all

1
aa
Output:

Code: Select all

A 2
But your code will not print a newline character. Just replace the following part

Code: Select all

      /*if(f==1 && min>0)
      {
         printf("\n");
      }
      f=1;*/
      count[letter]=-1;
      printf("%c %ld\n",letter,min); // notice that there is a newline character
Hope these help.

Re: 10008 - What's Cryptanalysis?

Posted: Tue May 27, 2008 4:23 pm
by sreejond
Thank you for your help jan vai.Now i got AC.

sreejon
cuet'06