题解 | #将真分数分解为埃及分数#

将真分数分解为埃及分数

http://www.nowcoder.com/practice/e0480b2c6aa24bfba0935ffcca3ccb7b

有1说1 我这个应该是最简单粗暴的解法了吧!!!

import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str = sc.nextLine();
            String[] strs = str.split("/");
            int num = Integer.parseInt(strs[0]);
            String res = "";
            for(int i=0;i<num;i++){
                res+="1/"+strs[1];
                if(i!=num-1){
                    res+="+";
                }
            }
            System.out.println(res);
        }
        
    }       
}
全部评论

相关推荐

05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务