[笔试] 设计一个新型的计算器 | 指尖的舞客
就是给出一个整数,将它的因子通过模拟七段管显示出来
Read full article from [笔试] 设计一个新型的计算器 | 指尖的舞客
就是给出一个整数,将它的因子通过模拟七段管显示出来
// 10,5 3
static
String[][] dict =
new
String[][] {
{
" - "
,
"| |"
,
" "
,
"| |"
,
" - "
},
// 0
{
" "
,
" |"
,
" "
,
" |"
,
" "
},
// 1
{
" - "
,
" |"
,
" - "
,
"| "
,
" - "
},
// 2
{
" - "
,
" |"
,
" - "
,
" |"
,
" - "
},
// 3
{
" "
,
"| |"
,
" - "
,
" |"
,
" "
},
// 4
{
" - "
,
"| "
,
" - "
,
" |"
,
" - "
},
// 5
{
" - "
,
"| "
,
" - "
,
"| |"
,
" - "
},
// 6
{
" - "
,
" |"
,
" "
,
" |"
,
" "
},
// 7
{
" - "
,
"| |"
,
" - "
,
"| |"
,
" - "
},
// 8
{
" - "
,
"| |"
,
" - "
,
" |"
,
" - "
} };
// 9
public
static
List<String> getPrime(Long num) {
List<String> list =
new
ArrayList<String>();
while
(num >
1
) {
for
(
int
i =
2
; i <= num; i++) {
if
(num % i ==
0
){
num = num / i;
list.add(String.valueOf(i));
break
;
}
}
}
return
list;
}
public
static
void
printList(List<String> list) {
if
(list.size()<
1
){
System.out.println();
return
;
}
for
(
int
j=
0
; j<
5
; j++){
for
(
int
i=
0
; i<list.size()-
1
; i++){
String tmp = list.get(i);
for
(
int
k=
0
;k<tmp.length(); k++){
System.out.print(dict[tmp.charAt(k) -
'0'
][j]);
}
if
(j==
2
){
System.out.print(
"*"
);
}
else
{
System.out.print(
" "
);
}
}
String tmp = list.get(list.size()-
1
);
for
(
int
k=
0
;k<tmp.length(); k++){
System.out.print(dict[tmp.charAt(k) -
'0'
][j]);
}
System.out.println();
}
}
public
static
void
main(String[] args) {
Scanner scanner =
new
Scanner(System.in);
while
(scanner.hasNext()){
long
num = scanner.nextLong();
List<String> list = getPrime(num);
printList(list);
}
}