题解 | #将真分数分解为埃及分数#只要通过就行,怎么简单怎么来
将真分数分解为埃及分数
http://www.nowcoder.com/practice/e0480b2c6aa24bfba0935ffcca3ccb7b
import java.util.Scanner;
/**
* @author xuxiang
* @date 2022/4/2 21:33
*/
/**
* 将真分数分解为埃及分数
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String[] sa = scanner.nextLine().split("/");
int f1 = Integer.parseInt(sa[0]);
int f2 = Integer.parseInt(sa[1]);
for (int i = 0; i < f1; i++) {
if (i + 1 < f1) {
System.out.print("1/" + f2 + "+");
} else {
System.out.println("1/" + f2);
}
}
}
}
}
/**
* @author xuxiang
* @date 2022/4/2 21:33
*/
/**
* 将真分数分解为埃及分数
*/
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()) {
String[] sa = scanner.nextLine().split("/");
int f1 = Integer.parseInt(sa[0]);
int f2 = Integer.parseInt(sa[1]);
for (int i = 0; i < f1; i++) {
if (i + 1 < f1) {
System.out.print("1/" + f2 + "+");
} else {
System.out.println("1/" + f2);
}
}
}
}
}