10008 - What's Cryptanalysis?
Moderator: Board moderators
-
- New poster
- Posts: 50
- Joined: Wed Nov 06, 2002 1:37 pm
- Location: Planet Earth, Universe
- Contact:
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
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
-
- New poster
- Posts: 8
- Joined: Wed Jan 25, 2006 6:25 pm
- Location: Dhaka, Bangladesh
10008 What's Cryptanalysis , Why WA???
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.
#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
Re: 10008 What's Cryptanalysis , Why WA???
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.
You code was failed.
![:(](./images/smilies/icon_frown.gif)
After you changed the code, if still get the wrong answer, post on this thread again.
Thank you.
10008 Compile Error
Ok, I am AC boy!!!
Last edited by Lotendil on Thu Feb 16, 2006 12:11 pm, edited 1 time in total.
ashik's code is allright in my machine
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?
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.
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.
ashik's code is allright in my machine
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
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.
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.
Re: ashik's code is allright in my machine
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 wrote:our code does not give proper output on some other machines...
Here's my code.. it gets WA each time
please check this out and give a response....
Thank u very much..[/code]
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.
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.
Thank u GURU
using scanf("%d\n"), i got acc.
my idea about "some other machines" was completely wrong.
Thank u very much.
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.
Undergraduate Student,
Department of Computer Science and Engineering,
Bangladesh University of Engineering and Technology, Dhaka.
-
- New poster
- Posts: 38
- Joined: Tue Jul 17, 2007 3:21 pm
- Location: East West University
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
Re: 10008 - What's Cryptanalysis?
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:
[Edited by Jan : Use code tags]
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;
}
Re: 10008 - What's Cryptanalysis?
Suppose the input is
Input:
Output:
But your code will not print a newline character. Just replace the following part
Hope these help.
Input:
Code: Select all
1
aa
Code: Select all
A 2
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
Ami ekhono shopno dekhi...
HomePage
HomePage
Re: 10008 - What's Cryptanalysis?
Thank you for your help jan vai.Now i got AC.
sreejon
cuet'06
sreejon
cuet'06