首页 > ACM题库 > HDU-杭电 > HDU 3248-Strange Clock[解题报告]HOJ
2014
03-09

HDU 3248-Strange Clock[解题报告]HOJ

Strange Clock

问题描述 :

There is a strange clock, without any number written. Can you tell me what time it is now, based on the angle of the hour hand?
Resource Archiver

When the hour hand points right (0 degree), it is 3 o’clock. When it points to 80 degrees, it’s between 0 o’clock and 1 o’clock. Note that there is no 12 o’clock. You should always write 0 o’clock instead.

输入:

There are at most 10 test cases. Each case contains a single integer a (0 <= a < 360), the angle of the hour hand. The input ends with a = -1.

输出:

There are at most 10 test cases. Each case contains a single integer a (0 <= a < 360), the angle of the hour hand. The input ends with a = -1.

样例输入:

90
245
-1

样例输出:

Exactly 0 o'clock
Between 6 o'clock and 7 o'clock

#include<stdio.h>
int main()
{
 int i=0;
 int n;
 int a;
 int sum,num;
 while(i<10)
 { 
 sum=num=0;
 scanf("%d",&a);
 if(a==-1)break;
 if(a==0) printf("Exactly 3 o'clock\n"); //���4
 else
 {
 sum=a%30;
 num=a/30;
 if(num<3) //���1
 {
 num=3-num;
 if(sum==0)
 printf("Exactly %d o'clock\n",num);
 if(sum!=0)printf("Between %d o'clock and %d o'clock\n",num-1,num);
 }
 if(num>3) //���2
 { 
 num=3-num+12;
 if(sum==0) printf("Exactly %d o'clock\n",num);
 if(sum!=0) printf("Between %d o'clock and %d o'clock\n",num-1,num);
 }
 if(num==3) //���3
 {
 num=3-num;
 if(sum==0) printf("Exactly %d o'clock\n",num);
 if(sum!=0) printf("Between %d o'clock and %d o'clock\n",11,num);
 
 }
 }
 i++;
 
 }
 return 0;
}

  1. 嗯 分析得很到位,确实用模板编程能让面试官对你的印象更好。在设置辅助栈的时候可以这样:push时,比较要push的elem和辅助栈的栈顶,elem<=min.top(),则min.push(elem).否则只要push(elem)就好。在pop的时候,比较stack.top()与min.top(),if(stack.top()<=min.top()),则{stack.pop();min.pop();},否则{stack.pop();}.

  2. 为什么for循环找到的i一定是素数叻,而且约数定理说的是n=p1^a1*p2^a2*p3^a3*…*pk^ak,而你每次取余都用的是原来的m,也就是n