Preface
刚刚在看到个C++的时钟面试题目,感觉挺简单的,写写玩玩儿吧,就当给自己复习。
有C风格和C++风格两种。
时钟与角度问题分析
时钟样子
时针与分针
有以下的特点:
- 1小时=60分钟
- 钟面有12格,每格角度:360°÷12h=30°/h
,即,每小时时针走过30°
- 60分钟走过一圈,每分钟角度:360°÷60/m=6°/m
,即,每小时分针走过6°
- 时针60分钟走一大格的时针,30°÷60/m=0.5°/m
,即,每分钟时针走0.5°
- 每分钟而言,分针比时针多走了6°-0.5°=5.5°
C风格的代码
//文件名:CStyleClock.cpp
#include <iostream>
#include <iomanip>
/*
* =====================================================================================
*
* Filename: another.cpp
*
* Description:
*
* Version: 1.0
* Created: 10/10/2016 02:44:39 PM
* Revision: none
* Compiler: clang++
*
* Author: Gabriel (Gabirel), Gabrielf977q@gmail.com
* Organization:
*
* =====================================================================================
*/
using namespace std;
//获得角度
double getAngle(int hour, int minute);
int main(int argc, char *argv[])
{
int hour, minute;
double angle;
while(cin