537 - Artificial Intelligence?

All about problems in Volume 5. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Fadia Ismael
New poster
Posts: 22
Joined: Wed Aug 17, 2005 3:04 pm

537- Artificial Intelligence WA, C++

Post by Fadia Ismael »

Hello every body....

Can any body tell me what is the error in my code??

the code is C++:

Code: Select all

removed
Thanks in advance..
Last edited by Fadia Ismael on Fri Nov 11, 2005 7:07 pm, edited 1 time in total.
It's lack of faith that makes people afraid of meeting challanges, and I believe in myself.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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..
Ami ekhono shopno dekhi...
HomePage
Fadia Ismael
New poster
Posts: 22
Joined: Wed Aug 17, 2005 3:04 pm

The same results...

Post 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??
It's lack of faith that makes people afraid of meeting challanges, and I believe in myself.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post 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... :D
Ami ekhono shopno dekhi...
HomePage
Fadia Ismael
New poster
Posts: 22
Joined: Wed Aug 17, 2005 3:04 pm

Thanks a lot...

Post by Fadia Ismael »

Thank you very very much.... I get it,,,, thanks a lot.... I get ACCEPTED..
:D
It's lack of faith that makes people afraid of meeting challanges, and I believe in myself.
Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

You are most welcome. And please select the edit option and remove your code...
Ami ekhono shopno dekhi...
HomePage
Dave
New poster
Posts: 5
Joined: Sat May 06, 2006 9:57 am
Location: England, My Chair

537

Post 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;
}
jainal cse du
New poster
Posts: 23
Joined: Thu Jul 27, 2006 2:43 pm
Location: University of Dhaka,Bangladesh

Post 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(...)'

--

Code: Select all

Code removed after AC.
[

Thanx
Last edited by jainal cse du on Sat Jul 21, 2007 3:54 pm, edited 1 time in total.
abdullah<cse du>
New poster
Posts: 39
Joined: Mon Dec 04, 2006 2:18 pm
Location: Bangladesh(CSE DU)
Contact:

Post by abdullah<cse du> »

Jainal,

I think problem in 'atof' function. Use <stdlib.h> for atof function.

I think this will help you.
ABDULLAH.
We were in past, we are in past and we will go in past.
jainal cse du
New poster
Posts: 23
Joined: Thu Jul 27, 2006 2:43 pm
Location: University of Dhaka,Bangladesh

Post by jainal cse du »

Thanx Abdulla.
Now I have got Accepted.
Obaida
A great helper
Posts: 380
Joined: Wed Jan 16, 2008 6:51 am
Location: (BUBT) Dhaka,Bagladesh.

Re: 537 - Artificial Intelligence

Post by Obaida »

Code: Select all

very silly mistake.. An easy problem..
:oops: :oops: :oops:

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.. :D
try_try_try_try_&&&_try@try.com
This may be the address of success.
Parksungsu
New poster
Posts: 5
Joined: Sun Aug 15, 2010 2:56 am

Re: 537 - Artificial Intelligence

Post 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.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 537 - Artificial Intelligence

Post 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.
Check input and AC output for thousands of problems on uDebug!
coder.bd
New poster
Posts: 2
Joined: Mon Jul 09, 2012 9:33 am

Re: 537 - Artificial Intelligence

Post by coder.bd »

Code: Select all

removed
uvasarker
Learning poster
Posts: 96
Joined: Tue Jul 19, 2011 12:19 pm
Location: Dhaka, Bangladesh
Contact:

Re: 537 - Artificial Intelligence

Post 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;
}

Post Reply

Return to “Volume 5 (500-599)”