现在的位置: 首页 > 综合 > 正文

HDOJ1061 Rightmost Digit

2016年09月28日 ⁄ 综合 ⁄ 共 300字 ⁄ 字号 评论关闭

原题链接

很经典的一道题,开始想着用二分法,结果超时,后来发现了规律,就搞定啦。

//找规律2014-3-11 18:40:19
#include <stdio.h>
#include <string.h>
char *sam[] = {"0", "1", "2486", "3971", "46", "5", "6", "7931", "8426", "91"};

int main(){
	int t, n, time;
	scanf("%d", &t);
	while(t--){
		scanf("%d", &n);
		time = n;
		n %= 10;
		printf("%d\n", sam[n][(time - 1) % strlen(sam[n])] - '0');
	}
	return 0;
}

抱歉!评论已关闭.