Page 3 of 6
537- Artificial Intelligence WA, C++
Posted: Wed Nov 09, 2005 10:14 pm
by Fadia Ismael
Hello every body....
Can any body tell me what is the error in my code??
the code is C++:
Thanks in advance..
Posted: Thu Nov 10, 2005 1:36 am
by Jan
Just try the I/O set... In my compiler your code returns wrong..
Input:
Code: Select all
3
U=120V and I=5.36A. What is the reason for calculating p? I cant understand ?
There was a p who has P=560W Which was destroyed by U=291.89V.
No chance if P=111.11W and I=3.004A.
Output:
Code: Select all
Problem #1
P=643.20W
Problem #2
I=1.92A
Problem #3
U=36.99V
Hope it works..
The same results...
Posted: Thu Nov 10, 2005 10:42 am
by Fadia Ismael
Hello... I tried your I/O and I have the same outputs of yours.... I don't know what is the error, can you please help??
Posted: Fri Nov 11, 2005 8:32 am
by Jan
I have already told you that your program returns wrong in my compiler version. Because you are printing 'double' with '%LF' (which is for 'long double'), You should use '%lf'. And your code returns 0.00 when the input
is like...
Input:
Code: Select all
3
U=200VI=4.5A.
U=220VP=100.00W.
P=2.5MWI=2A.
Output:
Code: Select all
Problem #1
P=900.00W
Problem #2
I=0.45A
Problem #3
U=1250000.00V
Best of Luck...

Thanks a lot...
Posted: Fri Nov 11, 2005 12:05 pm
by Fadia Ismael
Thank you very very much.... I get it,,,, thanks a lot.... I get ACCEPTED..

Posted: Fri Nov 11, 2005 6:50 pm
by Jan
You are most welcome. And please select the edit option and remove your code...
537
Posted: Tue May 16, 2006 5:23 pm
by Dave
I have got this code and tested it with all of the inputs found on these forums but I am still getting WA. Please Help
Code: Select all
#include <iostream>
#include <vector>
#include <string>
#include <ctype.h>
#include <iomanip>
#include <stdio.h>
using namespace std;
int numCases = 0;
float P, U, I;
char s[10000];
bool pgiven = false, ugiven = false, igiven = false;
bool first = true;
int main() {
cin >> numCases;
vector<string> prob(numCases+1);
for(int i = 0; i < numCases; i++)
{
if(first)
{
getchar();
first = false;
}
gets(s);
prob[i] = s;
}
for(int i = 0; i < numCases; i++)
{
int ppos = prob[i].find("P=") + 2;
int upos = prob[i].find("U=") + 2;
int ipos = prob[i].find("I=") + 2;
if(ppos != 1) {
pgiven = true;
string p;
int num = 0;
while(isdigit(prob[i].operator[](ppos+num)) || prob[i].operator[](ppos+num) == '.' || prob[i].operator[](ppos+num) == '-')
{
p = p + prob[i].operator[](ppos+num);
num++;
}
char* pdata = (char*)p.data();
P=atof(pdata);
if(prob[i].operator[](ppos+num) == 'M')
{
P = P * 1000000;
} else if(prob[i].operator[](ppos+num) == 'm')
{
P = P / 1000;
} else if(prob[i].operator[](ppos+num) == 'k')
{
P = P * 1000;
}
}
if(upos != 1) {
ugiven = true;
string u;
int num = 0;
while(isdigit(prob[i].operator[](upos+num)) || prob[i].operator[](upos+num) == '.' || prob[i].operator[](upos+num) == '-')
{
u = u + prob[i].operator[](upos+num);
num++;
}
char* udata = (char*)u.data();
U=atof(udata);
if(prob[i].operator[](upos+num) == 'M')
{
U = U * 1000000;
} else if(prob[i].operator[](upos+num) == 'm')
{
U = U / 1000;
} else if(prob[i].operator[](upos+num) == 'k')
{
U = U * 1000;
}
}
if(ipos != 1) {
igiven = true;
string is;
int num = 0;
while(isdigit(prob[i].operator[](ipos+num)) || prob[i].operator[](ipos+num) == '.' || prob[i].operator[](ipos+num) == '-')
{
is = is + prob[i].operator[](ipos+num);
num++;
}
char* idata = (char*)is.data();
I=atof(idata);
if(prob[i].operator[](ipos+num) == 'M')
{
I = I * 1000000;
} else if(prob[i].operator[](ipos+num) == 'm')
{
I = I / 1000;
} else if(prob[i].operator[](ipos+num) == 'k')
{
I = I * 1000;
}
}
cout.setf(ios::fixed, ios::floatfield);
cout.precision(2);
if(!igiven)
{
float ans = P / U;
cout << "Problem #" << i+1 << endl;
if(ans == -0)
cout << "I=" << 0.00 << "A" << endl << endl;
else
cout << "I=" << ans << "A" << endl << endl;
} else if(!ugiven)
{
float ans = P / I;
cout << "Problem #" << i+1 << endl;
if(ans == -0)
cout << "U=" << 0.00 << "V" << endl << endl;
else
cout << "U=" << ans << "V" << endl << endl;
} else if(!pgiven)
{
float ans = U * I;
cout << "Problem #" << i+1 << endl;
if(ans == -0)
cout << "P=" << 0.00 << "W" << endl << endl;
else
cout << "P=" << ans << "W" << endl << endl;
}
P = 0; U = 0; I = 0;
pgiven = false; ugiven = false; igiven = false;
ppos = 0; upos = 0; ipos = 0;
}
return 0;
}
Posted: Thu Jul 19, 2007 10:54 am
by jainal cse du
Can anybody tell me how I escape from Compile Error.
Here are the compiler error messages:
05754547_24.c: In function `int main()':
05754547_24.c:44: implicit declaration of function `int atof(...)'
--
[
Thanx
Posted: Fri Jul 20, 2007 5:57 am
by abdullah<cse du>
Jainal,
I think problem in 'atof' function. Use <stdlib.h> for atof function.
I think this will help you.
ABDULLAH.
Posted: Sat Jul 21, 2007 3:57 pm
by jainal cse du
Thanx Abdulla.
Now I have got Accepted.
Re: 537 - Artificial Intelligence
Posted: Mon Jul 13, 2009 7:38 pm
by Obaida
Code: Select all
very silly mistake.. An easy problem..
To every one there should be blank line after every case..
>>The output of jan vai don't show those blank line after last case.. That made me confused before getting acc...
Don't be confused..

Re: 537 - Artificial Intelligence
Posted: Wed Mar 14, 2012 5:56 pm
by Parksungsu
Hi, my name is Austin.
I got WA. but all the value is true.
I think that it is need to some exception.
So I want to know the exception.
like that It isn't -0.00, only print 0.00
please, reply to this sentence.
Re: 537 - Artificial Intelligence
Posted: Thu Mar 15, 2012 10:55 pm
by brianfry713
I didn't have any precision issues on this problem, my straightforward AC code uses C doubles, doesn't add an epsilon, and doesn't protect against negative zero.
Re: 537 - Artificial Intelligence
Posted: Mon Jul 09, 2012 9:43 am
by coder.bd
Re: 537 - Artificial Intelligence
Posted: Wed Aug 01, 2012 12:48 pm
by uvasarker
I am getting Wa. WHY? Help me please.
Code: Select all
#include <cstdio>
#include <cstring>
#include <cctype>
#include <iostream>
using namespace std;
int main()
{
int T, cas=0;
//freopen("in-537.txt","r",stdin);
//freopen("out-537.txt","w",stdout);
double P=0.0, U=0.0, I=0.0, tmp=0.0;
scanf("%d\n",&T);
while(T)
{
char s[10000], ch;
scanf("%s%c",s,&ch);
int ln=strlen(s), k=0, m=0, M=0, eq=0, PP=0, VV=0, II=0;
for(int i=0 ; i<ln ; i++)
{
if(s[i]=='=' && ( s[i-1]=='I' || s[i-1]=='P'|| s[i-1]=='U' ) && isdigit(s[i+1]) ) eq++;
//if(s[i]=='=') eq++;
}
float d=1.0;
if(eq>0)
{
long nm=0, dv=0, fag=0;
for(int i=0 ; i<ln ; i++)
{
if(s[i]=='m') m=1;
if(s[i]=='M') M=1;
if(s[i]=='k') k=1;
if(s[i]=='P') PP=1;
if(s[i]=='U') VV=1;
if(s[i]=='I') II=1;
if( s[i]>='0' && s[i]<='9' )
{
if(fag==1){dv=dv*10; d=(float)dv;}
nm=nm*10+(int)s[i]-48;
}
if( s[i]=='.' )
{
dv=1;
fag=1;
}
if(s[i]=='A' || s[i]=='W' || s[i]=='V')
{
tmp=(float)nm/d;
//printf("%lf m=%d M=%d k=%d\n",tmp,m,M,k);
if(PP==1){
P=tmp;
if(m==1) P=P/1000.0;
else if(M==1) P=P*1000000.0;
else if(k==1) P=P*1000.0;
}
else if(VV==1){
U=tmp;
if(m==1) U=U/1000.0;
else if(M==1) U=U*1000000.0;
else if(k==1) U=U*1000.0;
}
else if(II==1){
I=tmp;
if(m==1) I=I/1000.0;
else if(M==1) I=I*1000000.0;
else if(k==1) I=I*1000.0;
}
PP=0; VV=0; II=0; k=0; m=0; M=0;
nm=0; dv=0; fag=0; d=1.0;
}
}
}
if(ch=='\n'){
if(cas>0) printf("\n");
printf("Problem #%d\n",++cas);
if(P==0.0){
P=U*I;
printf("P=%.2lfW\n",P);
}
else if(U==0.0){
U=P/I;
printf("U=%.2lfV\n",U);
}
else if(I==0.0){
I=P/U;
printf("I=%.2lfA\n",I);
}
P=0.0; U=0.0; I=0.0; tmp=0.0;
T--;
}
}
return 0;
}