编程题【股神】

2017-04-28  本文已影响0人  yuanxiaolan
{UAIET@N[IQJ)V%)Z$7]9HV.png

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);      
        while(sc.hasNext()){
            int n=sc.nextInt();
            System.out.println(getPrice(n));
        }
    }

    public static int getPrice(int n) {
        int t=1;
        int m=2;
        int i=0;
        if(n<1){
            System.out.println("输入错误");
        }
        while(t<=n){
            t+=m;
            m++;
            if(t<=n){
                i++;
            }
        }
        return n-i*2;
    }
}

上一篇 下一篇

猜你喜欢

热点阅读