1 条题解

  • 0
    @ 2025-12-5 16:55:32

    C :

    #include<stdio.h>
    int main()
    {
     int x;
     while(scanf("%d",&x)!=EOF)
     {
      if(x<1)
      {
       printf("%d\n",x);
      }
      if(x>=1&&x<10)
      {
       printf("%d\n",2*x-1);
      }
      if(x>=10)
      {
        printf("%d\n",3*x-11);
      }
     }
    
     
    }
    
    

    C++ :

    #include<iostream>
    using namespace std;
    int main(){
    	int x,y;
        cin>>x;
        if(x<1) y=x;
    	if(x>1||x==1){
    		if(x<10)   y=2*x-1;
    		else   y=3*x-11;
    	}
    	cout<<y; 
    }
    

    Java :

    import java.util.Scanner;
    
    public class Main {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		Scanner input  = new Scanner(System.in);
    		int x = input.nextInt();
    		if(x < 1){
    			System.out.println(x);
    		}else if(x >= 1 && x < 10){
    			System.out.println(2*x-1);
    		}else{
    			System.out.println(3*x-11);
    		}
    	}
    
    }
    
    

    Python :

    def func(x):
        if(x<1):
            return x
        elif(x>=1 and x<10):
            return x*2-1
        else:
            return 3*x-11
    x=int(raw_input())
    
    print func(x)
    
    
    
    
    • 1

    信息

    ID
    1991
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者