10473 - Simple Base Conversion
Moderator: Board moderators
10473 wrong answer!!!
This ia my code!!
Can anyone tell me what wong with my code!!
thank you!!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
void main()
{
long int v,i;
double count,m,z;
char tran[12];
while(gets(tran))
{
z=count=v=0;
if(!strcmp(tran,"-1"))
break;
if(tran[0]=='0'&&tran[1]=='x')
{
for(i=strlen(tran)-1;i>=2;i--)
{
m=pow(16,count);
if(tran=='F')
m=m*15;
else if(tran=='E')
m=m*14;
else if(tran=='D')
m=m*13;
else if(tran=='C')
m=m*12;
else if(tran=='B')
m=m*11;
else if(tran=='A')
m=m*10;
else
m=m*((double)tran-'0');
count++;
z+=m;
}
printf("%.lf\n",z);
}
else
{
v=atoi(tran);
printf("0x%lX\n",v);
}
}
}
Can anyone tell me what wong with my code!!
thank you!!
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
void main()
{
long int v,i;
double count,m,z;
char tran[12];
while(gets(tran))
{
z=count=v=0;
if(!strcmp(tran,"-1"))
break;
if(tran[0]=='0'&&tran[1]=='x')
{
for(i=strlen(tran)-1;i>=2;i--)
{
m=pow(16,count);
if(tran=='F')
m=m*15;
else if(tran=='E')
m=m*14;
else if(tran=='D')
m=m*13;
else if(tran=='C')
m=m*12;
else if(tran=='B')
m=m*11;
else if(tran=='A')
m=m*10;
else
m=m*((double)tran-'0');
count++;
z+=m;
}
printf("%.lf\n",z);
}
else
{
v=atoi(tran);
printf("0x%lX\n",v);
}
}
}
my name is Lon
10473 : Output Limit Exceed
Hi.
I don't have any infinite loops in my code.. I don't understand the error...
Heres my code :
Input tested :
4
7
44
0x80685
0xABC
2748
0x1
0xABCDEF
123456
0x123456789
291
0x123
291
0xB
0xC
-1
Output :
0x4
0x7
0x2C
525957
2748
0xABC
1
11259375
0x1E240
2147483647
0x123
291
0x123
11
12
Can anyone see the problem?
Tanks
I don't have any infinite loops in my code.. I don't understand the error...
Heres my code :
Code: Select all
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main() {
char line[1000];
char aux[1000];
char *lixo;
int i;
scanf("%s\n",line);
do {
if (atoi(line) != -1) {
if (line[0] == '0' && line[1] == 'x') {
strcpy(aux, line);
i = strtol(aux, &lixo, 16);
printf("%d\n", i);
}
else
printf("0x%X\n", atoi(line));
scanf("%s\n",line);
}
} while(atoi(line)!=-1);
return 0;
}
4
7
44
0x80685
0xABC
2748
0x1
0xABCDEF
123456
0x123456789
291
0x123
291
0xB
0xC
-1
Output :
0x4
0x7
0x2C
525957
2748
0xABC
1
11259375
0x1E240
2147483647
0x123
291
0x123
11
12
Can anyone see the problem?
Tanks
-
- Experienced poster
- Posts: 183
- Joined: Thu Nov 11, 2004 12:35 pm
- Location: AIUB, Bangladesh
Well u have a BIIIIIIIIIIIG infinite loop.....
well ur code really give me hard time brother....I should have seen it earlier....when I could not find any logical error....I get back to the problem description.....and u know it always help.....
and what I found is that the programme will be terminated by a negative decimal value not necessarily with -1 all the time....
so u should do: atoi(line)>=0 instead of doing atoi(line)!=-1 in both of the places....and ur code got Accepted when I changed it......R U HAPPY NOW?
Goodluck.....see u later on......

well ur code really give me hard time brother....I should have seen it earlier....when I could not find any logical error....I get back to the problem description.....and u know it always help.....

and what I found is that the programme will be terminated by a negative decimal value not necessarily with -1 all the time....

so u should do: atoi(line)>=0 instead of doing atoi(line)!=-1 in both of the places....and ur code got Accepted when I changed it......R U HAPPY NOW?
Goodluck.....see u later on......

Jalal : AIUB SPARKS
HI.
Tanks for replying.
In fact, i haven't notest that problem of the decimal integer
Tanks
I've tested it but now I got Wrong Answer
I think that the judge doesn't like me 
Tanks for replying.
In fact, i haven't notest that problem of the decimal integer

I've tested it but now I got Wrong Answer

Code: Select all
(...)
if (atoi(line) >= 0) {
if (line[0] == '0' && line[1] == 'x') {
(...)
} while(atoi(line)>=0);
(...)

-
- Experienced poster
- Posts: 183
- Joined: Thu Nov 11, 2004 12:35 pm
- Location: AIUB, Bangladesh
Hey....come on.....
dont be so frustrated....
how did u submit ur code.....do u use somekind of mail service like yahoo or hotmail? may be thats the reason why u r getting WA.....
i just copy-paste ur code in the judge submitter and just changed the sign to (>=0) from (!=-1) and it got Acc again right now.
always use the submit-o-matic software in the main window " submit your code here " u will see it, never mail ur code and becareful about the correct problem number......10473
there cant be any other reason for ur WA...ur code is ok and got AC twice
(shall I submit it for u?
)

how did u submit ur code.....do u use somekind of mail service like yahoo or hotmail? may be thats the reason why u r getting WA.....
i just copy-paste ur code in the judge submitter and just changed the sign to (>=0) from (!=-1) and it got Acc again right now.
always use the submit-o-matic software in the main window " submit your code here " u will see it, never mail ur code and becareful about the correct problem number......10473
there cant be any other reason for ur WA...ur code is ok and got AC twice


Jalal : AIUB SPARKS
ID Date (UTC) Status CPU Memory Author Source Problem / Title
3077610 2004/11/15 16:38:38.860 Wrong Answer 0:00.051 64 53936 C 10473 - Simple Base Conversion
3076771 2004/11/15 09:16:31.100 Wrong Answer 0:00.051 64 53936 C 10473 - Simple Base Conversion
3076766 2004/11/15 09:14:10.539 Wrong Answer 0:00.055 392 53936 C 10473 - Simple Base Conversion
I think I'me getting crazy
[c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main() {
char line[1000];
char aux[1000];
char *lixo;
int i;
scanf("%s\n",line);
do {
if (atoi(line) >= 0) {
if (line[0] == '0' && line[1] == 'x') {
strcpy(aux, line);
i = strtol(aux, &lixo, 16);
printf("%d;\n", i);
}
else
printf("0x%X;\n", atoi(line));
scanf("%s\n",line);
}
} while(atoi(line)>=0);
return 0;
}
[/c]
3077610 2004/11/15 16:38:38.860 Wrong Answer 0:00.051 64 53936 C 10473 - Simple Base Conversion
3076771 2004/11/15 09:16:31.100 Wrong Answer 0:00.051 64 53936 C 10473 - Simple Base Conversion
3076766 2004/11/15 09:14:10.539 Wrong Answer 0:00.055 392 53936 C 10473 - Simple Base Conversion
I think I'me getting crazy

[c]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
int main() {
char line[1000];
char aux[1000];
char *lixo;
int i;
scanf("%s\n",line);
do {
if (atoi(line) >= 0) {
if (line[0] == '0' && line[1] == 'x') {
strcpy(aux, line);
i = strtol(aux, &lixo, 16);
printf("%d;\n", i);
}
else
printf("0x%X;\n", atoi(line));
scanf("%s\n",line);
}
} while(atoi(line)>=0);
return 0;
}
[/c]
-
- Experienced poster
- Posts: 183
- Joined: Thu Nov 11, 2004 12:35 pm
- Location: AIUB, Bangladesh




have a look u have extra semi colons in ur printf function, just before the '\n' and thats the reason for ur WA.....I dont know why u did it....but u know it happens sometimes, when things get wrong. But no matter never lose hope. I m in good form now-a-days. sometime it also happens to me.
your country will be proud of u if u dont lose confidence and keep trying no matter what happens......

I hope u get Ac this time, and if not, I will be back

Jalal : AIUB SPARKS
For anyone who may need some
sample I/O on problem 10473.
The dots in the sample input
below represent ( should be replaced by )
spaces.
The last two lines of the sample input contain the
decimal and the hexadecimal representation of
the number N = 2^31 - 1
INPUT
OUTPUT
sample I/O on problem 10473.
The dots in the sample input
below represent ( should be replaced by )
spaces.
The last two lines of the sample input contain the
decimal and the hexadecimal representation of
the number N = 2^31 - 1
INPUT
Code: Select all
..0..
...0x0....
1
2
3
..4...
10
11
12
13
14
15
...16
17
44
..64
...0x80685...
0x1
0x2
0x3
0x4
...0x10..
0x11
0xA
0xB
...0xF...
0xFF
....................2147483647....
....0x7FFFFFFF...
-5
OUTPUT
Code: Select all
0x0
0
0x1
0x2
0x3
0x4
0xA
0xB
0xC
0xD
0xE
0xF
0x10
0x11
0x2C
0x40
525957
1
2
3
4
16
17
10
11
15
255
0x7FFFFFFF
2147483647
it's horrible easy to solve this using C/C++
here's the part that shows advantage of C++;D
Regards
here's the part that shows advantage of C++;D
Code: Select all
if(strlen(line)>=3 && line[0] == '0' && line[1] == 'x') //then num is in hexdecimal system
{
line[0] = line[1] = ' ';
sscanf(line,"%x",&num);
printf("%d\n",num);
}
else //decimal system
{
sscanf(line,"%d",&num);
printf("0x%X\n",num);
}
keep it real!
10473 compiler error ? WHY
Here is my code
I can compile it in GCC of Freebsd and devc
but why compiler error?
I can compile it in GCC of Freebsd and devc
but why compiler error?
Code: Select all
#include<string>
#include<iostream>
#include<sstream>
#include<iomanip>
using namespace std;
int main() {
string input;
int loc_x,loc_neg,d;
while(cin>>input) {
loc_neg=input.find("-",0);
loc_x=input.find("0x",0);
if(loc_neg!=string::npos) {
if(loc_x!=string::npos) {
istringstream(input) >> hex >> d;
cout << dec << d << endl;
}
else break;
}
else {
if(loc_x!=string::npos) {
istringstream(input) >> hex >> d;
cout << dec << d << endl;
}
else {
istringstream(input) >> d;
cout << "0x" << hex << uppercase << d << endl;
}
}
}
return 0;
}