579 - Clock Hands

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

efr_shovo
New poster
Posts: 38
Joined: Wed Sep 22, 2004 9:09 am

Post by efr_shovo » Sat Oct 02, 2004 7:31 am

Thanks Man I got Accepted Now

User avatar
Sedefcho
A great helper
Posts: 374
Joined: Sun Jan 16, 2005 10:18 pm
Location: Bulgaria

Post by Sedefcho » Mon Feb 28, 2005 3:11 am

Hi !

The I/O was useful for me too.

Thank you, Ghust_omega !

Lord Nemrod
New poster
Posts: 12
Joined: Mon Mar 28, 2005 7:55 pm
Contact:

579 - WHAT"S WRONG???!!!!

Post by Lord Nemrod » Mon Mar 28, 2005 8:02 pm

I've been trying to sord out what's wrong with this problem for two weeks, but in vain - WA:( . Can you please help me?

Here's the code:

#include "iostream.h"
#include "stdio.h"
#include "iomanip.h"

double GetAngle(int Hour, int Min);


int main(int argc, char* argv[])
{
int i=0;
int Hour = 0;
int Min = 0;
char* time = new char[10];
cout<<setiosflags(ios::fixed|ios::showpoint)<<setprecision(3);
while(true)
{
cin>>time;
sscanf(time,"%i:%i", &Hour, &Min);
if(Hour==0)
{
break;
}
if(Hour==12)
{
Hour = 0;
}
cout<<GetAngle(Hour, Min)<<"\n";
}

delete [] time;

return 0;
}



double GetAngle(int Hour, int Min)
{
double HourAngle = 30*Hour + (double)Min/2.0;
double MinAngle = 6*Min;

double Angle = HourAngle-MinAngle;
if(Angle<0)
Angle*=-1;
if(Angle>180)
Angle = 360 - Angle;
return Angle;
}
[/b]

Raiyan Kamal
Experienced poster
Posts: 106
Joined: Thu Jan 29, 2004 12:07 pm
Location: Bangladesh
Contact:

Post by Raiyan Kamal » Wed Mar 30, 2005 6:20 pm

Dear Lord Nemrod,
I tried to compare your code and mine with some test cases, but could not find any difference between the outputs. This is strange that your code is getting WA. Do you mail your code to the OJ ? then try using the submit o matic.

The only case where I found your output to differ with mine is :

12 <some spaces> : <some spaces> 00

The output should be 0.000 but your program terminates on reaching this point. I am not sure if this is a valid input or not, but it is always better to be cautious.

I did not see any output formatting in your code. May be using

Code: Select all

printf("%.3f",angle);
will do the trick. There is no harm in trying.

elgeish
New poster
Posts: 3
Joined: Mon Mar 01, 2004 12:36 am

Post by elgeish » Sun Jul 10, 2005 6:31 pm

i've tried ur input and i got ur ACC output but it gives WA???

Code: Select all

#include <stdio.h>

void main() {
	int H, M;
	float A;

	while( scanf( " %i : %i", &H, &M ) && ( H || M ) ) {
		A = H * 30 + M / 2.0f - M * 6;
		A = A < 0 ? -A : A;
		printf( "%.3f\n", A > 180 ? 360.0 - A : A );
	}
}

ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

579 WHY TLE???

Post by ranban282 » Wed May 17, 2006 5:04 pm

Here's the code

Code: Select all

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<list>
#include<queue>
#include<cctype>
using namespace std;

int main()
{
	
	string s;
	int  hr,m;
	char temp;
	while(cin>>s)
	{
		
		if(s=="0:00")
			break;
	if(s.length()==4)
	{
		hr=s[0]-'0';
		m=(s[2]-'0')*10+s[3]-'0';
	}	
	else if(s.length()==5)
	{
		hr=s[1]-'0'+10*(s[0]-'0');
		
		m=(s[3]-'0')*10+s[4]-'0';
	}	
	else
		break;
	if(hr==0 && m==0)
		break;
	long double hr1=(long double)hr;
		long double m1=(long double) m;
		printf("%0.3Lf\n",min(fabs(hr1*30.0+m1/2.0-m1*6.0),360.0-fabs(hr1*30.0+m1/2.0-m1*6.0)));
	}	
	return 0;
}

Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko » Wed May 17, 2006 7:18 pm

Looking at your code, maybe there are some whitespaces around? If last line is " 0:00" it will never exit? I am not sure how reading behind EOF works in C++ (Java would crash).

ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

HI,

Post by ranban282 » Thu May 18, 2006 3:07 am

Could you be a bit more specific? As in what kind of inputs are expected?

ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

I modify the program, still i get TLE...

Post by ranban282 » Thu May 18, 2006 3:24 am

#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<list>
#include<queue>
#include<cctype>
using namespace std;

int main()
{

string s;
while(getline(cin,s,'\n'))
{


int hr=0,m=0;
string::iterator i;

for(i=s.begin();i!=s.end()&&*i!=':';i++)
{
if(isdigit(*i))
hr=hr*10+*i-'0';
}
for(;i!=s.end();i++)
{
if(isdigit(*i))
m=m*10+*i-'0';
}


if(hr==0 )
break;
long double hr1=(long double)hr;
long double m1=(long double) m;
printf("%0.3Lf\n",min(fabs(hr1*30.0+m1/2.0-m1*6.0),360.0-fabs(hr1*30.0+m1/2.0-m1*6.0)));
}
return 0;
}

ranban282
New poster
Posts: 37
Joined: Tue May 02, 2006 1:01 pm
Contact:

Hi

Post by ranban282 » Thu May 18, 2006 1:40 pm

Thx all, my code got accepted....
You will not believe it.....
The error was caused by using fabs.
The moment i removed it it started working.
Does anyone know why that happens?

User avatar
comaniac
New poster
Posts: 2
Joined: Sun Jul 22, 2007 7:24 pm
Location: Taiwan,Taipei
Contact:

Post by comaniac » Sun Jul 22, 2007 7:28 pm

Thanks a lot!
I found that my code has a small problem through your data
now i got "Accept",thanks.

P.S. That data was created by another random program?

euleramon
New poster
Posts: 6
Joined: Sun Feb 27, 2005 7:02 am

579 - ClockHands

Post by euleramon » Sun Sep 21, 2008 3:44 pm

Could anyone give me some tips about my code ? I just tested my program with others' test data without problems. But I got the RE(Runtime Error) from Uva system. Please tell me what's wrong with my program.

Code: Select all


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define NUM 9999
int  main()
{
	int h[NUM], m[NUM], i=0;
	double h_hand[NUM], m_hand[NUM], angle[NUM];

	scanf("%d:%d",&h[i], &m[i]);
	while(m[i]!=0 || h[i]!=0)
	{
		h_hand[i] = h[i]*30.0 + m[i]/2.0;
		m_hand[i] = m[i]*6.0;
		angle[i] = fabs(h_hand[i]-m_hand[i]);
		
		if(angle[i]>180.0)
			angle[i] = 360.0 - angle[i];

	//	printf("%.3f\n",angle[i]);

		i++;
		scanf("%d:%d",&h[i], &m[i]);
	}

	for(int j=0; j<i; j++)
	{
		printf("%.3f\n",angle[j]);
	}
	return 0;
}

Before One Piece

euleramon
New poster
Posts: 6
Joined: Sun Feb 27, 2005 7:02 am

Re: 579 - ClockHands

Post by euleramon » Mon Sep 22, 2008 2:21 am

I just removed the arrays like "[NUM]", and modified my I/O to one output following one input. Then, I got AC. Although I ever kept arrays and modified my I/O to one output following one input similarly, I still got RE. I thought there is sth wrong with my array. Anyway thank everyone for skimming over my code. :wink:
Before One Piece

jk4837
New poster
Posts: 3
Joined: Sat Aug 04, 2007 6:44 am

579 - ClockHands WA ><

Post by jk4837 » Wed Dec 09, 2009 6:51 am

I got WA in 579-ClockHands, but can't find any error.
Please help me!

My code:

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;

int main()
{
double h,m;
int i;
string c;
cin >> c;
if(c.substr(0,4)=="0:00")
exit(0);
while(1)
{
h=0;
i=0;
double s;
while(isdigit(c))
h=h*10+int(c[i++]-48);
m=int(c[++i]-48)*10+int(c[++i]-48);
//cout << h << " : " << m << endl;
if(h==0 && m==0)
break;
s= m-(h*5.0+m/12)*6;
s= s<0 ? -s : s;
if(s>180)
s=360-s;
cout << fixed << showpoint << setprecision(3) << s ;
cin >> c;
if(c.substr(0,4)!="0:00")
cout << endl;
else
break;
}
return 0;
}

saiful_islam
New poster
Posts: 6
Joined: Tue Feb 08, 2011 7:41 pm

Re: 579 - ClockHands

Post by saiful_islam » Thu Mar 10, 2011 5:27 pm

Why WA plz help

Code: Select all

#include<stdio.h>
int main()
{
	//freopen("G:\\in.txt","r",stdin);
	//freopen("G:\\out.txt","w",stdout);
	
	long double B,a,d[100];
	while(1)
	{
	char c;
	int m,h,b,M,u=1,i=1,k;
	scanf("%d%c%d",&h,&c,&m);
	if(h==0)
	return 0;
	M= (int) m/5;
	b=m%5;
	a=(long double) m*6;
	if(h>=M)
	{
		B=(long double) (h-M)*5*6-(b*6)+(30*a/360);
		if(B>180)
		{
			printf("%.3Lf\n",360-B);
		}
		else
			printf("%.3Lf\n",B);
	}
	else 
	{
		B=(long double) ((M-h)*5*6+(b*6)-(30*a/360));
		if(B>180)
		{
			printf("%.3Lf\n",360-B);
		}
		else
			printf("%.3Lf\n",B);

	}
	}
	return 0;
}

Post Reply

Return to “Volume 5 (500-599)”