Page 2 of 4
10473 wrong answer!!!
Posted: Sat Jun 05, 2004 6:07 am
by Lon
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);
}
}
}
Posted: Tue Jul 20, 2004 5:19 pm
by sidky
Just consider this case:
0xB
0xC
whose output should be:
11
12
10473 : Output Limit Exceed
Posted: Fri Nov 12, 2004 11:36 am
by coolzero
Hi.
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;
}
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
Posted: Mon Nov 15, 2004 6:32 am
by CodeMaker
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......

Posted: Mon Nov 15, 2004 11:19 am
by coolzero
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
Code: Select all
(...)
if (atoi(line) >= 0) {
if (line[0] == '0' && line[1] == 'x') {
(...)
} while(atoi(line)>=0);
(...)
I think that the judge doesn't like me

Posted: Mon Nov 15, 2004 5:31 pm
by CodeMaker
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?

)
Posted: Mon Nov 15, 2004 6:37 pm
by coolzero
I'll try again...
Because of me the reputation of country is going down!

Posted: Mon Nov 15, 2004 6:40 pm
by coolzero
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]
Posted: Mon Nov 15, 2004 8:26 pm
by CodeMaker

Hello Brother.....weeeell I got wrong answer this time

But I also found the error in ur new code....

well I told u to change >=0, not to put extra ' ;' in ur printf();
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

Posted: Mon Nov 15, 2004 8:36 pm
by coolzero
I put the semicolon just to see if there was any garbage on the printf's and I forget to take it off!!
Accepted now
Tanks
Posted: Tue Nov 16, 2004 4:24 am
by CodeMaker

You got Acc....Happy to hear that...
Goodluck, things may work just fine from now
Posted: Thu Feb 24, 2005 6:03 pm
by Sedefcho
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
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
Posted: Mon Jun 13, 2005 11:28 pm
by jaracz
it's horrible easy to solve this using C/C++
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);
}
Regards
10473 compiler error ? WHY
Posted: Tue Aug 09, 2005 11:29 am
by ansiemens
Here is my code
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;
}
Posted: Tue Aug 09, 2005 2:06 pm
by kai
I've got the following error with g++-2.95:
tmp.cc: In function `int main()':
tmp.cc:27: `uppercase' undeclared (first use this function)
tmp.cc:27: (Each undeclared identifier is reported only once
tmp.cc:27: for each function it appears in.)