import java.util.Scanner; public class Main {     public static void main(String[] args) {         Scanner sc = new Scanner(System.in) ;         while (sc.hasNextInt()){             int x = sc.nextInt() ;             int step = 0 ;             int cur = 0 ;             int bs = 1 ;             while (cur != x){                 step++ ;                 if(cur > x ){                     if(cur-bs>=x){                         cur = cur-bs ; //向左跳                     }                     else{                         cur = cur+bs ; //向右跳                     }                 }else{                     if(cur+bs <= x){                         cur = cur+bs ; //向右跳                     }                     else                         cur = cur-bs ; //向左跳                 }                 bs++ ;             }             System.out.println(step);         }     } } 我忘记过了多少了, 但是很少,不知道该怎么改了...
点赞 评论

相关推荐

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