ACM问题 我的代码哪里错了?? http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1361
http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1361Themotionofthehandsofa...
http://acm.swjtu.edu.cn/JudgeOnline/showproblem?problem_id=1361
The motion of the hands of a clock is mesmerizing. The second hand revolves once a minute, the minute hand revolves once an hour, and the hour hand revolves once every 12 hours. Have you ever wondered what the exact angles of the hands are at a given time?
Input
Each line of the input file contains a clock time, expressed in hours, minutes, and seconds. Each number in the time appears in a two column field, separated by single colons. Hours are between 1 and 12, and minutes and seconds are between 0 and 59.
Output
For each time input, Output the time and compute the exact angle of the hour, minute and second hands. Express the angles in degrees clockwise from straight up, at least 0.0 and less than 360.0. Format the output as shown in the sample below.
Sample Input
6:00:00
8:30:00
10:17:55
Sample Output
At 6:00:00...
Hour hand orientation: 180.00 degrees,
Minute hand orientation: 0.00 degrees,
Second hand orientation: 0.00 degrees.
At 8:30:00...
Hour hand orientation: 255.00 degrees,
Minute hand orientation: 180.00 degrees,
Second hand orientation: 0.00 degrees.
At 10:17:55...
Hour hand orientation: 308.96 degrees,
Minute hand orientation: 107.50 degrees,
Second hand orientation: 330.00 degrees.
我的代码:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int h,m,s;
char ch;
while(cin>>h>>ch>>m>>ch>>s)
{
printf("At %d:%2.2d:%2.2d...\n",h,m,s);
printf(" Hour hand orientation: %.2lf degrees,\n",(double)(h*3600+m*60+s)/(double)(3600*12)*360);
printf("Minute hand orientation: %.2lf degrees,\n",(double)(m*60+s)/(double)(3600)*360);
printf("Second hand orientation: %.2lf degrees.\n\n",(double)s/(double)(60)*360);
}
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int h,m,s;
char ch;
while(cin>>h>>ch>>m>>ch>>s)
{
printf("At %d:%2.2d:%2.2d...\n",h,m,s);
printf(" Hour hand orientation: %.2lf degrees,\n",30*h+0.5*m+0.5/(double)60*s);
printf("Minute hand orientation: %.2lf degrees,\n",6*m+(double)0.1*s);
printf("Second hand orientation: %.2lf degrees.\n\n",(double)6*s);
}
return 0;
}
二楼这个也不对哈 这个题好像是输出格式问题哈 帮忙看看 展开
The motion of the hands of a clock is mesmerizing. The second hand revolves once a minute, the minute hand revolves once an hour, and the hour hand revolves once every 12 hours. Have you ever wondered what the exact angles of the hands are at a given time?
Input
Each line of the input file contains a clock time, expressed in hours, minutes, and seconds. Each number in the time appears in a two column field, separated by single colons. Hours are between 1 and 12, and minutes and seconds are between 0 and 59.
Output
For each time input, Output the time and compute the exact angle of the hour, minute and second hands. Express the angles in degrees clockwise from straight up, at least 0.0 and less than 360.0. Format the output as shown in the sample below.
Sample Input
6:00:00
8:30:00
10:17:55
Sample Output
At 6:00:00...
Hour hand orientation: 180.00 degrees,
Minute hand orientation: 0.00 degrees,
Second hand orientation: 0.00 degrees.
At 8:30:00...
Hour hand orientation: 255.00 degrees,
Minute hand orientation: 180.00 degrees,
Second hand orientation: 0.00 degrees.
At 10:17:55...
Hour hand orientation: 308.96 degrees,
Minute hand orientation: 107.50 degrees,
Second hand orientation: 330.00 degrees.
我的代码:
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int h,m,s;
char ch;
while(cin>>h>>ch>>m>>ch>>s)
{
printf("At %d:%2.2d:%2.2d...\n",h,m,s);
printf(" Hour hand orientation: %.2lf degrees,\n",(double)(h*3600+m*60+s)/(double)(3600*12)*360);
printf("Minute hand orientation: %.2lf degrees,\n",(double)(m*60+s)/(double)(3600)*360);
printf("Second hand orientation: %.2lf degrees.\n\n",(double)s/(double)(60)*360);
}
return 0;
}
#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int h,m,s;
char ch;
while(cin>>h>>ch>>m>>ch>>s)
{
printf("At %d:%2.2d:%2.2d...\n",h,m,s);
printf(" Hour hand orientation: %.2lf degrees,\n",30*h+0.5*m+0.5/(double)60*s);
printf("Minute hand orientation: %.2lf degrees,\n",6*m+(double)0.1*s);
printf("Second hand orientation: %.2lf degrees.\n\n",(double)6*s);
}
return 0;
}
二楼这个也不对哈 这个题好像是输出格式问题哈 帮忙看看 展开
展开全部
这题的问题是, 时针角度要小于360度, 你输入 12:00:00就知道问题出在哪了.
另外注意格式.
1361 Accepted 184K 15MS G++ 1.23K
#include<iostream>
#include<cstdlib>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Fori(x) for (int i=0; i<(x); i++)
#define Forj(x) for (int j=0; j<(x); j++)
#define Fork(x) for (int k=0; k<(x); k++)
#define Forij(x, y) Fori(x) Forj(y)
#define Clear(x) (memset((x), 0, sizeof(x)))
#define Bound(x, y, bx, by) (((x)>=0&&(x)<bx&&(y)>=0&&(y)<by) ? true : false)
const int NUL = -1;
const int dim[4][2] = {0, -1, -1, 0, 0, 1, 1, 0};
int ni, nj;
//////////////////////// vars /////////////////////////////
int h, m, s;
//////////////////////// functions ////////////////////////
//////////////////////// main /////////////////////////////
int main()
{
double t;
while (scanf("%d:%d:%d", &h, &m, &s) == 3)
{
printf("At %d:%.2d:%.2d...\n", h, m, s);
t = (double)(3600*h+60*m+s)*360 / (3600*12);
if (t >= 360) t -= 360;
printf(" Hour hand orientation: %6.2lf degrees,\n", t);
printf("Minute hand orientation: %6.2lf degrees,\n", (double)(60*m+s)*360 / 3600);
printf("Second hand orientation: %6.2lf degrees.\n\n", (double)s*6);
}
return 0;
}
另外注意格式.
1361 Accepted 184K 15MS G++ 1.23K
#include<iostream>
#include<cstdlib>
#include<iostream>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
#define Fori(x) for (int i=0; i<(x); i++)
#define Forj(x) for (int j=0; j<(x); j++)
#define Fork(x) for (int k=0; k<(x); k++)
#define Forij(x, y) Fori(x) Forj(y)
#define Clear(x) (memset((x), 0, sizeof(x)))
#define Bound(x, y, bx, by) (((x)>=0&&(x)<bx&&(y)>=0&&(y)<by) ? true : false)
const int NUL = -1;
const int dim[4][2] = {0, -1, -1, 0, 0, 1, 1, 0};
int ni, nj;
//////////////////////// vars /////////////////////////////
int h, m, s;
//////////////////////// functions ////////////////////////
//////////////////////// main /////////////////////////////
int main()
{
double t;
while (scanf("%d:%d:%d", &h, &m, &s) == 3)
{
printf("At %d:%.2d:%.2d...\n", h, m, s);
t = (double)(3600*h+60*m+s)*360 / (3600*12);
if (t >= 360) t -= 360;
printf(" Hour hand orientation: %6.2lf degrees,\n", t);
printf("Minute hand orientation: %6.2lf degrees,\n", (double)(60*m+s)*360 / 3600);
printf("Second hand orientation: %6.2lf degrees.\n\n", (double)s*6);
}
return 0;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询