回复 10楼 书生牛犊
第五题:最后两位数实际上是一个循环。这里分开问也就是想提醒大伙存在这么一个循环。个位数只存在2,4,6,8这4个数值。同理,最后两位数也存在类似的一个循环。
当然,你说的方法适合不同整数的N次方取最后两位的运算。
通过这题,就是想说。往往看适复杂的东西,只要你理解它的规则,其实它并不难。
[此贴子已经被作者于2016-11-4 09:46编辑过]
[此贴子已经被作者于2016-11-4 09:55编辑过]

程序代码:#include <stdio.h>
inline int foo( int n )
{
static const int map[] = { 1,2,4,8,16,32,64,28,56,12,24,48,96,92,84,68,36,72,44,88,76,52 };
return map[(n-2)%20+2];
}
int main( void )
{
printf( "%02d\n", foo(1992) );
}
程序代码:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
srand((unsigned)time(NULL));
char ch=0;
int comp=0;
int man=0;
char * s[]={"石头","剪子","布"};
while(1)
{
fflush(stdin);
system("cls");
printf("请选择你要出的拳头:\n");
printf("A:石头\n");
printf("B:剪子\n");
printf("C:布\n");
printf("D:退出\n");
scanf("%c",&ch);
if(ch=='d' || ch=='D') break;
comp=rand()%3;
if(ch=='a' || ch=='A') man=0;
if(ch=='b' || ch=='B') man=1;
if(ch=='c' || ch=='C') man=2;
if(comp-man==0) printf("电脑出的是%s 平局\n",s[comp]);
if((comp-man==-1) || (comp-man==2)) printf("电脑出的是%s 电脑胜出\n",s[comp]);
if((comp-man==1) || (comp-man==-2)) printf("电脑出的是%s 楼主胜出\n",s[comp]);
system("pause");
}
return 0;
}
[此贴子已经被作者于2016-11-4 14:42编辑过]

[此贴子已经被作者于2016-11-4 15:52编辑过]