579 - Clock Hands
Moderator: Board moderators
-
- New poster
- Posts: 12
- Joined: Mon Mar 28, 2005 7:55 pm
- Contact:
579 - WHAT"S WRONG???!!!!
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]
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]
-
- Experienced poster
- Posts: 106
- Joined: Thu Jan 29, 2004 12:07 pm
- Location: Bangladesh
- Contact:
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 usingwill do the trick. There is no harm in trying.
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);
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 );
}
}
579 WHY TLE???
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;
}
HI,
Could you be a bit more specific? As in what kind of inputs are expected?
I modify the program, still i get TLE...
#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;
}
#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;
}
Hi
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?
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?
579 - ClockHands
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
Re: 579 - ClockHands
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:](./images/smilies/icon_wink.gif)
![:wink:](./images/smilies/icon_wink.gif)
Before One Piece
579 - ClockHands WA ><
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;
}
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;
}
-
- New poster
- Posts: 6
- Joined: Tue Feb 08, 2011 7:41 pm
Re: 579 - ClockHands
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;
}