1 条题解

  • 0
    @ 2023-6-11 12:19:05

    C :

    #include<stdio.h>
    #include<limits.h>
    int a[1001];
    int main(){
    	int n,i,mi=INT_MAX,mx=INT_MIN;
    	scanf("%d",&n);
    	for(i=1;i<=n;i++){
    		scanf("%d",&a[i]);
    	}
    	for(i=1;i<=n;i++){
    		if(a[i]<mi){
    		   mi = a[i];
    		}
    		if(a[i]>mx){
    			mx=a[i];
    		}
    	}
    	for(i=1;i<=n;i++){
    		if(a[i]==mx){
    			printf("%d ",a[i]*2);
    		}else if(a[i]==mi){
    			printf("%d ",a[i]+1);
    		}else{
    			printf("%d ",a[i]);
    		}
    	}
    	return 0;
    }
    

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
    	int a[1010],n,i,ma,mi;
    	cin>>n;
    	for(i = 0;i < n;i++){
    		cin>>a[i];
    	} 
    	
    	ma = a[0];
    	mi = a[0];
    	for(i = 1;i < n;i++){
    		if(a[i] > ma){
    			ma = a[i];
    		}
    		
    		if(a[i] < mi){
    			mi = a[i];
    		}
    	} 
    	
    	for(i = 0;i < n;i++){
    		if(a[i] == ma){
    			a[i] = a[i] * 2;
    		}else if(a[i] == mi){
    			a[i] = a[i] + 1;
    		}
    	}
    	
    	for(i = 0;i < n;i++){
    		cout<<a[i]<<" ";
    	} 
    	return 0;
    }
    
    

    Java :

    
    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int num1 = scanner.nextInt();
    //        int num2 = scanner.nextInt();
            int[] a = new int[num1];
            double s = 0,avg;
            for (int i = 0; i < num1; i++) {
                a[i] = scanner.nextInt();
            }
            int m = MAX(a);
            for (int i = 0; i < num1; i++) {
                if(m == a[i]){
                        a[i] = a[i] * 2;
                }else if(MIN(a) == a[i]) a[i] = a[i] + 1;
            }
            for (int i = 0; i < num1; i++) {
                System.out.print(a[i] + " ");
            }
    
        }
    
        public static boolean judge(int i,int j){
            int a,s = 0;
            while(i != 0){
                a = i % 10;
                s = s + a;
                i /= 10;
            }
            if(s == j)return true;
            else return false;
        }
    
        public static void paiXu(int[] a){
            int temp;
            for(int i = 0;i < a.length - 1;i++){
                for(int k = 0;k < a.length - i - 1;k++){
                    if(a[k] > a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        }
    
        public static int MAX(int[] a){
            int max = a[0];
            for (int i = 0; i < a.length; i++) {
                if(max < a[i]){
                    max = a[i];
                }
            }
            return max;
        }
    
        public static int MIN(int[] a){
            int min = a[0];
            for (int i = 0; i < a.length; i++) {
                if(min > a[i]){
                   min = a[i];
                }
            }
            return min;
        }
    }
    

    Python :

    # 接收输入整数n
    n = int(input())
    # n个数字放入字符串列表m中
    m = input().split()
    # 字符串列表转换为整型列表
    for i in range(0, n):
        m[i] = int(m[i])
    # 求列表中最大值mx
    mx = max(m)
    mi = min(m)
    for i in range(0, n):
        if m[i] == mx:
            m[i] = 2 * mx
        if m[i] == mi:
            m[i] = mi + 1
    #循环列表,输出最终数字
    for i in range(0, n):
        print(m[i], end=' ')
    
    • 1

    信息

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