zoukankan      html  css  js  c++  java
  • Java实现 洛谷 P1010 幂次方

    在这里插入图片描述

    输入输出样例
    输入 #1

    1315
    

    输出 #1

    2(2(2+2(0))+2)+2(2(2+2(0)))+2(2(2)+2(0))+2+2(0)
    
    import java.util.Scanner;
    
    public class Main {
        public static void main(String[] args) {
    		Scanner sc= new Scanner(System.in);
    		int a=sc.nextInt();
    		pow(a);
    	}
        public static void pow(int a){
        	 if(a>3){
        		 int s=0;
        		 int b=2;
        		 while(b<=a){
        			 b=b*2;
        			 s++;
        		 }
        		 a=a-b/2;
        		 System.out.print("2(");
        		 pow(s);
        		 
        		 if(s==3){
        			 System.out.print("2+2(0)");
        		 }
        		 if(s==1){
        			 System.out.print("2(0)");
        		 }
        		 if(s==2){
        			 System.out.print("2");
        		 }
        	
        		 System.out.print(")");
        		
        		 if(a==3){
        			 System.out.print("+2+2(0)");
        		 }
        		 if(a==1){
        			 System.out.print("+2(0)");
        		 }
        		 if(a==2){
        			 System.out.print("+2");
        		 }
        		 if(a>3){
        		 System.out.print("+");}
        		 pow(a);
        	 }
        	 
        }
    }
    
    
  • 相关阅读:
    php文件 基本语法
    DBDA类 连接数据库 返回Json 返回字符串
    全选复选框做法
    弹窗js
    AJAX
    弹窗JS CSS
    JavaScript
    链接数据库 类
    PHP 分页 查询
    Foreach嵌套Foreach
  • 原文地址:https://www.cnblogs.com/a1439775520/p/13076652.html
Copyright © 2011-2022 走看看