10008 - What's Cryptanalysis?

All about problems in Volume 100. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

sidky
New poster
Posts: 50
Joined: Wed Nov 06, 2002 1:37 pm
Location: Planet Earth, Universe
Contact:

Post by sidky » Fri Sep 02, 2005 8:17 pm

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

ashikzinnatkhan
New poster
Posts: 8
Joined: Wed Jan 25, 2006 6:25 pm
Location: Dhaka, Bangladesh

10008 What's Cryptanalysis , Why WA???

Post by ashikzinnatkhan » Thu Jan 26, 2006 5:44 pm

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.
Ashik

tan_Yui
Experienced poster
Posts: 155
Joined: Sat Jul 10, 2004 12:41 am

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

Post by tan_Yui » Sun Jan 29, 2006 2:25 pm

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.

Lotendil
New poster
Posts: 3
Joined: Thu Feb 16, 2006 1:12 am

10008 Compile Error

Post by Lotendil » Thu Feb 16, 2006 1:16 am

Ok, I am AC boy!!!
Last edited by Lotendil on Thu Feb 16, 2006 12:11 pm, edited 1 time in total.

chunyi81
A great helper
Posts: 293
Joined: Sat Jun 21, 2003 4:19 am
Location: Singapore

Post by chunyi81 » Thu Feb 16, 2006 6:12 am

You need to #include <cctype> to use functions such as isalpha

And remove this code after you get AC.

eyeabhi
New poster
Posts: 11
Joined: Fri Apr 28, 2006 4:16 pm
Location: Bangladesh
Contact:

ashik's code is allright in my machine

Post by eyeabhi » Wed May 03, 2006 6:55 pm

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 Roy
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.

eyeabhi
New poster
Posts: 11
Joined: Fri Apr 28, 2006 4:16 pm
Location: Bangladesh
Contact:

ashik's code is allright in my machine

Post by eyeabhi » Wed May 03, 2006 6:56 pm

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
Abhishek Roy
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Re: ashik's code is allright in my machine

Post by mamun » Wed May 03, 2006 7:48 pm

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.

eyeabhi
New poster
Posts: 11
Joined: Fri Apr 28, 2006 4:16 pm
Location: Bangladesh
Contact:

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

Post by eyeabhi » Wed May 03, 2006 8:20 pm

please check this out and give a response....
Thank u very much..[/code]
Last edited by eyeabhi on Thu May 04, 2006 9:55 am, edited 1 time in total.
Abhishek Roy
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.

mamun
A great helper
Posts: 286
Joined: Mon Oct 03, 2005 1:54 pm
Location: Bangladesh
Contact:

Post by mamun » Thu May 04, 2006 6:37 am

Both of you've done almost the same thing for input. Instead of flushing the input buffer just write
scanf("%d\n", &lines);

eyeabhi
New poster
Posts: 11
Joined: Fri Apr 28, 2006 4:16 pm
Location: Bangladesh
Contact:

Thank u GURU

Post by eyeabhi » Thu May 04, 2006 9:04 am

using scanf("%d\n"), i got acc.
my idea about "some other machines" was completely wrong.
Thank u very much.
Abhishek Roy
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.

User avatar
Fuad Hassan EWU
New poster
Posts: 38
Joined: Tue Jul 17, 2007 3:21 pm
Location: East West University

Post by Fuad Hassan EWU » Sat Sep 15, 2007 6:44 pm

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;
}
Eagle er moto daana meley urbo

User avatar
sreejond
New poster
Posts: 32
Joined: Fri May 23, 2008 6:16 pm
Contact:

Re: 10008 - What's Cryptanalysis?

Post by sreejond » Mon May 26, 2008 7:43 pm

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]

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Re: 10008 - What's Cryptanalysis?

Post by Jan » Mon May 26, 2008 8:20 pm

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.
Ami ekhono shopno dekhi...
HomePage

User avatar
sreejond
New poster
Posts: 32
Joined: Fri May 23, 2008 6:16 pm
Contact:

Re: 10008 - What's Cryptanalysis?

Post by sreejond » Tue May 27, 2008 4:23 pm

Thank you for your help jan vai.Now i got AC.

sreejon
cuet'06

Post Reply

Return to “Volume 100 (10000-10099)”