1 条题解

  • 0
    @ 2025-10-10 15:45:57

    C :

    #include <stdio.h>
    void main()
    {
    	int n,b,s,g,t;
    	scanf("%d",&n);
    	b=n/100;
    	s=n%100/10;
    	g=n%10;
    	if(b>s){
    		t=b;
    		b=s;
    		s=t;
    	}	
    	if(s>g){
    		t=s;
    		s=g;
    		g=t;
    	}
    	if(b>s){
    		t=b;
    		b=s;
    		s=t;
    	}
    	if(b==0){
    		t=b;
    		b=s;
    		s=t;	
    	}
    	printf("%d",b*100+s*10+g);
    }
    

    C++ :

    #include <bits/stdc++.h>
    
    using namespace std;
    
    int main(){
    	int t,n,a,b,c;
    	cin>>n;
    	a=n/100;
    	b=n/10%10;
    	c=n%10;
    	if(a>b){
    		t=a;
    		a=b;
    		b=t;
    	}
    	
    	if(b>c){
    		t=c;
    		c=b;
    		b=t;
    	}
    	
    	if(a>b){
    		t=a;
    		a=b;
    		b=t;
    	}
    	
    	if(a==0&&b==0){
    		cout<<c*100+a*10+b<<endl;
    	}
    	else if(a==0){
    		cout<<b*100+a*10+c<<endl;
    	}
    	else{
    		cout<<a*100+b*10+c<<endl;
    	}
    }
    

    Java :

    import java.util.Scanner;
    public class Main {
    	public static void main(String[] args) {
    		Scanner sc = new Scanner(System.in);
    		int x = sc.nextInt() ;
    		int temp = 0;
    		int a  = x % 10;
    		int b  = x / 10 % 10;
    		int c  = x / 100;
    		if(a != 0 & b != 0 & c != 0 ) {
    			if(a > b) {
    				temp = a;
    				a = b;
    				b = temp;
    			}
    			if(b > c) {
    				temp = b;
    				b = c;
    				c = temp;
    			}
    			if(a > b) {
    				temp = a;
    				a = b;
    				b = temp;
    			}
    			temp = a * 100 + b * 10 + c;
    			
    		}
    		if(a == 0 ) {
    			if(b > c) {
    				temp = c * 100 + b;
    			}else {
    				temp = b * 100 + c;
    				}
    			}
    		if( b == 0 ) {
    			if( a > c) {
    				temp = c * 100 + a;
    			}else {
    				temp = a * 100 + c;
    			}
    			
    		}
    		if( c == 0 ) {
    			if( b > c) {
    				temp = c * 100 + b;
    			}else {
    				temp = b * 100 + c;
    			}
    			
    		}
    		System.out.println(temp);
    	}
    }
    
    
    
    
    

    Python :

    n = int(input())
    # a>b>c
    a = n // 100;
    b = n // 10 % 10;
    c = n % 10;
    if a < b:
        t=a
        a=b
        b=t 
    if a < c:
        t=a
        a=c
        c=t 
    if b < c:
        t=b
        b=c
        c=t
    if c != 0:
        print(c*100+b*10+a)
    elif b == 0 and c == 0:
        print(a*100)
    elif c == 0:
        print(b*100 + a)
    
    • 1

    【入门】请求出一个3位数打乱次序后能组成的最小的3位数是多少?

    信息

    ID
    238
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    1
    已通过
    1
    上传者