AcWing 3463. 乘法口诀数列
原题链接
简单
作者:
Yeahhh
,
2021-05-04 22:17:21
,
所有人可见
,
阅读 454
使用队列
(队头两个元素乘积入队,再把队头出队输出)
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.Scanner;
public class Main {
static Deque<Integer> q = new ArrayDeque<>();
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int a1 = in.nextInt();
int a2 = in.nextInt();
int n = in.nextInt();
q.addLast(a1);
q.addLast(a2);
for (int i = 0; i < n; i++) {
System.out.print(q.getFirst() + " ");
int x = q.pollFirst() * q.getFirst();
if (x < 10) q.addLast(x);
else {
q.addLast(x / 10);
q.addLast(x % 10);
}
}
}
}