Page **1** of **4**

### 10019 - Funny Encryption Method

Posted: **Sun Jun 30, 2002 1:44 am**

by **gix**

I get a sigsev on this source:

#include <stdio.h>

#include <iostream>

#include <stdlib.h>

#include <unistd.h>

#include <fcntl.h>

int mypow (int b, int exp)

{

int res = b;

if (exp==0)

return 1;

while (exp>1)

{

res = res * b;

exp --;

}

return res;

}

int main (void)

{

#ifndef ONLINE_JUDGE

close (0); open ("10019.in", O_RDONLY);

close (1); open ("10019.out", O_WRONLY | O_CREAT, 0600);

#endif

int n, i;

int number[256], dimn;

char achar;

int X1, X2;

unsigned int b1, b2;

cin >> n;

scanf ("%c", &achar); /* skip new line */

while (n>0)

{

n--;

dimn=0;

scanf ("%c", &achar);

while (achar!='\n')

{

number[dimn] = achar - 48;

dimn++;

scanf("%c", &achar);

}

X1 = X2 = 0;

for (i=0; i<dimn; i++)

{

X1 += number

* * mypow(10, dimn-i-1);*

X2 += number* * mypow(16, dimn-i-1);*

}

b1 = b2 = 0;

for (i=0; i<14; i++)

{

if ( ( X1 & (1<<i) ) == (1<<i) )

b1++;

if ( ( X2 & (1<<i) ) == (1<<i) )

b2++;

}

cout << b1 << " " << b2 << endl;

}

return 0;

}

the problem seem to be in these lines:

while (achar!='\n')

{

number[dimn] = achar - 48;

dimn++;

scanf("%c", &achar);

}

uhmmm but what is wrong on these lines ? ...

thanks for reading my orrible english!

good night

GiGi

Posted: **Sun Jun 30, 2002 8:56 am**

by **Picard**

you shouldn't mix C++ iostream with FILE i/o. input and output can be different, but don't use iostream and FILE for the same purpose.

one solution: replace all scanf("%c",..) with ...=cin.get().

hint1: i whould change the reading process to watch out for blank or eof

hint2: is 2^13 really the highest bit possible in X1, X2?

### ok, solved!

Posted: **Sun Jun 30, 2002 4:14 pm**

by **gix**

thanks a lot, I suppose the problem was on blank or EOF checks ... Maybe I've to study iostream better

but why 14 bits wasn't too much?

if 0<M<9999 and 2^14 = 16384 I think 14 bits are enogh (ok 13 were few

... But when I try to submit my source with the following lines:

for (i=0; i<15; i++)

{

if ( ( X1 & (1<<i) ) == (1<<i) )

b1++;

if ( ( X2 & (1<<i) ) == (1<<i) )

b2++;

}

... I get a WA! doh!

Posted: **Sun Jun 30, 2002 5:12 pm**

by **Picard**

65536 > 0x9999 > 32768

### decimal or hexadecimal?

Posted: **Sun Jun 30, 2002 8:59 pm**

by **gix**

but the problem says:

"Each of the following N Lines ( 0<N<=1000) will contain the number M (0<M<=9999, in decimal representation)"

....

?????

mah

maybe I should try another hobby

Posted: **Sun Jun 30, 2002 9:08 pm**

by **10153EN**

Just quoted from the problem description (I think you should know also

):

[quote]1) Read the number N to encrypt M = 265

2) Interpret N as a decimal number X1= 265 (decimal)

3) Convert the decimal interpretation of N to its binary representation X1= 100001001 (binary)

4) Let b1 be equal to the number of 1

Posted: **Mon Oct 14, 2002 3:48 am**

by **XeoNite**

How am I supposed to deal with hexadecimals such as 2B2 or 3E9. Basicly any with letters. If I just convert them value by value to binary and count the amount of 1s I get the wrong answer.

And I have no idea how to do it any other way. Some hints/help, please and thanks.

[edit]

Stumbled onto a solution by looking in a math guidebook. Didn't know that hex letters had a numeric equivelency.

### 10019 - Little help

Posted: **Sun Jun 22, 2003 7:58 pm**

by **Trinity**

People!

I`m getting a compiler error, just need a help w/ the output format

I`m working w/ java.

[java]System.out.println(funnyCryp.binario(dados

*)+" "+funnyCryp.hexadecimal(dados**));}}}*

[/java]

The error is in that space <" ">

But the answer must come w/ 2 separate numbers (5 6)...

I got confused....

Could I get some help please?! I mean, Can`t I use spaces???

Thanx a lot

Trinity

Posted: **Sun Jun 22, 2003 11:05 pm**

by **zsepi**

trinity,

I'd say that that line shouldn't be the reason why you get compiler error... check out the judge's info pages about JAVA, 'coz I believe they aren't using the sun java compiler, but the gcj - read more about JAVA support:

http://acm.uva.es/problemset/java.html
http://acm.uva.es/problemset/howtows.html#java
or you could send me your code in private, and I could have a look at it

cheers!

### Outputs?!

Posted: **Mon Jun 23, 2003 2:59 pm**

by **Trinity**

Guys!

I think I'm writting wrong my outputs...

I'm getting a compiler error in both programs a tried to submit, but I don't know what is...

program: 10019

[java]public static void main(String[] args)

{

FunnyCryption funnyCryp = new FunnyCryption();

int input = funnyCryp.input();

int dados[] = new int[input+1];

for (int i=1; i <= input; i++)

{

dados*=funnyCryp.input();*

}

for (int i=1; i <= input; i++)

{

System.out.println(funnyCryp.binario(dados*)+" "+funnyCryp.hexadecimal(dados**));*

}

}

[/java]

ERROR

/tmp/ccAKmd2Omain.o: In function `main':

/tmp/ccSzJJ2nmain.i(.text+0x12): undefined reference to `_CL_4Main'

collect2: ld returned 1 exit status

and program: 10107

[java]/*x is the lastest array's position.

This method is called inside a loop that goes from the first to the last element of the input data

Example input = [4,3,5,1,7,2]. Is called with 0, then 1, then 2 (the position of the last element

that will be considered to find the median*/

if (x%2!=0)

{

num = Math.abs(x/2);

v1 = valor2[num];

v2 = valor2[num+1];

mediana = Math.abs((v1+v2)/2);

System.out.println(mediana);

}

else

{

num = (x/2);

{mediana = valor2[num];}

System.out.println(mediana);

}

[/java]

ERROR

/tmp/cc4xonPrmain.o: In function `main':

/tmp/ccYsGgxfmain.i(.text+0x12): undefined reference to `_CL_4Main'

collect2: ld returned 1 exit status

Does anyone knows what is???!!!

Thanx

Trinity

Posted: **Mon Jun 23, 2003 6:35 pm**

by **Trinity**

Another one guys!!!

I solve that one, was not about the space, I think it was going something wrong by e-mail, then I changed some things and worked

But now shows this error...

[java]public static void main(String[] args)

{

FunnyCryption funnyCryp = new FunnyCryption();

int input = funnyCryp.input();

int dados[] = new int[input+1];

for (int i=1; i <= input; i++)

{

dados*=funnyCryp.input();*

}

for (int i=1; i <= input; i++)

{

int bin = funnyCryp.binario(dados*);*

int hexa = funnyCryp.hexadecimal(dados*);*

System.out.println(bin+" "+hexa);

}

}[/java]

/tmp/ccAKmd2Omain.o: In function `main':

/tmp/ccSzJJ2nmain.i(.text+0x12): undefined reference to `_CL_4Main'

collect2: ld returned 1 exit status

The other program I tied to submit came w/ the same error...

I REALLY NEED THE HELP, PLEASE....

THANX

TRINITY

### is your class named Main?

Posted: **Mon Jun 23, 2003 7:42 pm**

by **hectorzeta**

I thought I had the same problem and it was because the class must be named Main. And it could be the reason of get a compiler error.

Posted: **Wed Jun 25, 2003 2:57 pm**

by **Moni**

Hai! Are you meant binary() ???

Then tell me how the compiler will behave

[java]funnyCryp.binario(dados

*)+" "+funnyCryp.hexadecimal(dados**)); [/java]*

Clear!

### 10019 - Compile Error

Posted: **Wed Jul 02, 2003 11:07 am**

by **r.z.**

Why is my code resulting compil error?

I run it with Borland C 3.1 and there's no warning or error message

can you tell me what's wrong?

[c]

#include<stdio.h>

#include<string.h>

#include<stdlib.h>

int pangkat(int a);

void main()

{ int m,i,j,b1,b2,n,p1,p2,temp;

char a1[100],a2[100];

while(scanf("%d",&n)!=EOF)

{

for(j=0;j<n;j++)

{ b1=0;

b2=0;

scanf("%d",&m);

itoa(m,a1,2);

p1=strlen(a1);

for(i=0;i<p1;i++)

{ if(a1*=='1')*

b1+=1;

}

itoa(m,a2,10);

p2=strlen(a2);

temp=0;

for(i=0;i<p2;i++)

{ temp+=(a2*-48)*pangkat(p2-1-i);*

}

itoa(temp,a2,2);

p2=strlen(a2);

for(i=0;i<p2;i++)

{ if(a2*=='1')*

b2+=1;

}

printf("%d %d\n",b1,b2);

}

}

}

int pangkat(int a)

{ if(a==0) return 1;

if(a==1) return 16;

if(a==2) return 256;

if(a==3) return 4096;

return -1;

}

[/c]

thanks

### 10019

Posted: **Tue May 31, 2005 7:05 pm**

by **asif_rahman0**

Hello,I can't understand the problem 10019.Actually,what to do.So,anybody plz help me to understand the problem.