446 - Kibbles "n" Bits "n" Bits "n" Bits
Moderator: Board moderators
It seems you are new. I think you should carefully examine the following code. Actually this problem is a very easy one.
[cpp]
#include<stdio.h>
void printbinary13(int x);
void printbinary13(int x){
int c,v=0x1000;
for(c=0;c<13;c++){
if(x&v)putchar('1');else putchar('0');
v>>=1;
}
}
void main(){
int a,b,n,i,r;
char op;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%X %c %X",&a,&op,&b);
if(op=='+')r=a+b;else r=a-b;
printbinary13(a);
printf(" %c ",op);
printbinary13(b);
printf(" = %d\n",r);
}
}
[/cpp]
[cpp]
#include<stdio.h>
void printbinary13(int x);
void printbinary13(int x){
int c,v=0x1000;
for(c=0;c<13;c++){
if(x&v)putchar('1');else putchar('0');
v>>=1;
}
}
void main(){
int a,b,n,i,r;
char op;
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%X %c %X",&a,&op,&b);
if(op=='+')r=a+b;else r=a-b;
printbinary13(a);
printf(" %c ",op);
printbinary13(b);
printf(" = %d\n",r);
}
}
[/cpp]
μδ. ταηνιπ αλ αμιη
shamim
wat is difference between %X %x at the time of scanf():
will u tell me please.
as i know it can fell effect at the time of printf();
will u tell me please.
as i know it can fell effect at the time of printf();
thanx popel
sorry i misunderstood shamim talk.
i know that wont fell effect. that y i asked that.
i know that wont fell effect. that y i asked that.
446 > Kibbles `n' Bits `n' Bits `n' Bits > Help!.
Greetings!.
I thought this wasn't going to be a tough problem, but I'm having a hard time trying to solve it
Need help. I've tested it with Input from forum, and it seems to work, but I keep getting WAs from all modifications I've made to it.
[pascal]{ Bernardo E. L
I thought this wasn't going to be a tough problem, but I'm having a hard time trying to solve it

Need help. I've tested it with Input from forum, and it seems to work, but I keep getting WAs from all modifications I've made to it.
[pascal]{ Bernardo E. L
_.
not valid
For the above inputs:2
0 - FFF
FFF + FFF
I don't think the first one is valid and thus will not be in the judge's data..
... for the second one my AC program outputs:
0111111111111 + 0111111111111 = 8190
Thanks. And still need help :)
Thanks for the quick response sohel!.
Wanted to be sure no negative responses were allowed.
Still need to know what's wrong with my program
What am I missing??
Wanted to be sure no negative responses were allowed.
Still need to know what's wrong with my program

What am I missing??

_.
I am not a pascal coder but you can try the following input/output:
Input:
[c]
10
A + B
FFF - 123
36 + 2
0 + 0
3 - 0
23 - 1
A46 - 1A
F - 1
14 - 13
988 - FA
[/c]
output
[c]
0000000001010 + 0000000001011 = 21
0111111111111 - 0000100100011 = 3804
0000000110110 + 0000000000010 = 56
0000000000000 + 0000000000000 = 0
0000000000011 - 0000000000000 = 3
0000000100011 - 0000000000001 = 34
0101001000110 - 0000000011010 = 2604
0000000001111 - 0000000000001 = 14
0000000010100 - 0000000010011 = 1
0100110001000 - 0000011111010 = 2190
[/c]
Input:
[c]
10
A + B
FFF - 123
36 + 2
0 + 0
3 - 0
23 - 1
A46 - 1A
F - 1
14 - 13
988 - FA
[/c]
output
[c]
0000000001010 + 0000000001011 = 21
0111111111111 - 0000100100011 = 3804
0000000110110 + 0000000000010 = 56
0000000000000 + 0000000000000 = 0
0000000000011 - 0000000000000 = 3
0000000100011 - 0000000000001 = 34
0101001000110 - 0000000011010 = 2604
0000000001111 - 0000000000001 = 14
0000000010100 - 0000000010011 = 1
0100110001000 - 0000011111010 = 2190
[/c]
Thanks!, but still...
Thanks again sohel!.
My program throws the exact same answer as posted by you and others in other posts
Either one of us is going insane, me or the OnlineJudge
Because I just tried to solve problem 499 and got the same stats for the WA as I got for the 3 WAs for the 446:
Wrong Answer - 0:00.002 - 64
My program throws the exact same answer as posted by you and others in other posts

Either one of us is going insane, me or the OnlineJudge

Because I just tried to solve problem 499 and got the same stats for the WA as I got for the 3 WAs for the 446:
Wrong Answer - 0:00.002 - 64
_.
Accepted!.
Thanks for the help sohel!.
Tried to make it in a different way, and found out the mistake was in reading the #13 and #26.
Now I'm changing to eoLn and eoF and getting ACs!.
Keep posting!.
Tried to make it in a different way, and found out the mistake was in reading the #13 and #26.
Now I'm changing to eoLn and eoF and getting ACs!.
Keep posting!.
_.
-
- New poster
- Posts: 6
- Joined: Sun Jan 23, 2005 8:21 pm
446 - Returning a string...
So... I am having difficulty returning a string...
I used a pointer...
The output I get is
I used a pointer...
to point to my input string.. I debugged the program under VC6.0 and pt handles the right string.. the problem is that its content is not properly returned...char *pt;
Code: Select all
#include <stdio.h>
char *bin(int num);
main()
{
int i,n,hex1,hex2;
char op;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%X %c %X",&hex1,&op,&hex2);
printf("%s %c %s = %d\n",bin(hex1),op,bin(hex2),op=='+' ? hex1+hex2 : hex1-hex2);
}
}
char *bin(int num)
{
char temp[13]="0000000000000",*pt=temp;
int i=12;
while(num!=0)
{
temp[i]=48+num%2;
num=num/2;
i--;
}
temp[13]=0;
return pt;
}
C:\Valladolid\Debug>446 < 446.txt
♀
-
- Guru
- Posts: 584
- Joined: Thu Jun 19, 2003 3:48 am
- Location: Sanok, Poland
- Contact:
446 - WA!!
Hello, I solved this problem and all I/O test I've seen in all posts are OK in my program, But I can't get AC .... Can any one give me some criticals I/O for this problem? ...
Here's my code, am I missing something?
___________________
[_TANG_]

Here's my code, am I missing something?
Code: Select all
#include <iostream.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
char *binario[16] = {"0000","0001","0010","0011","0100","0101","0110","0111","1000","1001","1010","1011","1100","1101","1110","1111"};
void cambia_hex_bin(char*,char*);
int cambia_bin_dec(char*);
void main()
{
char hex1[5], hex2[5], op[1];
int num1, num2, c, n;
cin >> n;
for(c = 0; c < n; c++)
{
char temp[14] = {'\0'};
cin>> hex1 >> op >> hex2;
cambia_hex_bin(hex1,temp);
num1 = cambia_bin_dec(temp);
cout << temp << " " << op;
memset(temp,'\0',14);
cambia_hex_bin(hex2,temp);
num2 = cambia_bin_dec(temp);
cout << " " << temp << " = ";
if(strcmp(op,"+") == 0)
cout << num1 + num2 << endl;
else
cout << num1 - num2 << endl;
}
}
int cambia_bin_dec(char *bin)
{
int c, pos = 0;
double suma = 0.0;
for(c = strlen(bin)-1; c >= 0; c--, pos++)
if(bin[pos] == '1')
suma += pow(2,c);
return (int)suma;
}
void cambia_hex_bin(char *hex, char *bin)
{
int c = 0, len;
strcat(bin,"0");
len = strlen(hex);
for(c = len; c < 3; c++)
strcat(bin,"0000");
c = 0;
while(hex[c])
{
if(isalpha(hex[c]))
strcat(bin,binario[hex[c] - 55]);
else
strcat(bin,binario[hex[c] - 48]);
c++;
}
}
[_TANG_]