1 条题解

  • 0
    @ 2023-6-11 12:17:13

    C :

    #include<stdio.h>
    
    void main(){
    	int a[100][100];
    	int i,j,n,m,t=0,g,s,b,q;
    	scanf("%d %d",&n,&m);
    	
    	for(i=0;i<n;i++){
    		for(j=0;j<m;j++){
    			scanf("%d",&a[i][j]);
    		}
    	}
    	
    	for(i=0;i<n;i++){
    		for(j=0;j<m;j++){
    			g=a[i][j]%10;
    			s=a[i][j]/10%10;
    			b=a[i][j]/100%10;
    			q=a[i][j]/1000;
    			if((g+s+b+q)%2!=0){
    				t++;
    			}
    		}
    	}
    	
    	printf("%d",t);
    }
    

    C++ :

    #include <iostream>
    using namespace std;
    
    int main(){
    	int a[200][200],i,j,n,m,c = 0,g,s,b,q,w;
    	cin>>n>>m;
    	
    	for(i = 0;i < n;i++){
    		for(j = 0;j < m;j++){
    			cin>>a[i][j];
    			g = a[i][j] % 10;
    			s = a[i][j] / 10 % 10;
    			b = a[i][j] / 100 % 10;
    			q = a[i][j] / 1000;
    			
    			if((g + s + b + q) % 2 == 1){
    				c++;
    			}
    		} 
    	}
    	
    	cout<<c<<endl;
    }
    
    
    

    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][num2];
            int x = 0;
            for (int i = 0; i < num1; i++) {
                for(int k = 0;k < num2;k++){
                    a[i][k] = scanner.nextInt();
                    if(sum(a[i][k]) % 2 != 0)x++;
                }
            }
            System.out.println(x);
    
    
    
        }public static void paiXu(int[] a,int length){
            int temp;
            for(int i = 0;i < length - 1;i++){
                for(int k = 0;k < length - i - 1;k++){
                    if(a[k] > a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        } public static void paiXud(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 void paiXux(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 MAX2(int[][] a){
            int max = a[0][0];
            for (int i = 0; i < a.length; i++) {
                for(int j = 0;j < a[0].length;j++){
                    if(max < a[i][j])max = a[i][j];
                }
            }
            return max;
        }public static int MIN2(int[][] a){
            int min = a[0][0];
            for (int i = 0; i < a.length; i++) {
                for(int j = 0;j < a[0].length;j++){
                    if(min > a[i][j])min = a[i][j];
                }
            }
            return min;
        }
        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;
        }
        public static int sum(int a){
            int x,s = 0;
            while(a != 0){
                x = a % 10;
                s = s + x;
                a /= 10;
            }
            return s;
        }
        public static boolean isPrime(int a){
            if(a <= 1)return false;
            else
            for(int i = 2;i <= Math.sqrt(a);i++){
                if(a % i == 0)return false;
            }return true;
        }
    
        public static long qiuYu(long i){
            long a;
            a = i % 10;
            return a;
        }
        public static int daoXu(int x){
            int s = 0,m;
            while(x != 0){
                m = x % 10;
                s = s * 10 + x;
                x /= 10;
            }
            return s;
        }
    
        public static int jiaWei(int x){
            int s = 0,m;
            while(x != 0){
                m = x % 10;
                s = s + m;
                x /= 10;
            }
            return s;
        }
    
        public static int fun(int x){
            if(x == 1 || x == 2)return 1;
            else return fun(x - 1) + fun(x - 2);
        }
    }
    

    Python :

    #定义一个数求各位数字之和的函数
    def cw(x):
        su = 0
        # 短除法拆位,求拆位后各位的和su
        while x > 0:
            su += x % 10
            x //= 10
        return su
    
    
    s = input().split()
    # 行数n
    n = int(s[0])
    # 列数m
    m = int(s[1])
    c = 0
    a = [[0 for j in range(m)] for i in range(n)]
    #循环接收输入
    for i in range(n):
        t = input().split()
        for j in range(m):
            a[i][j] = int(t[j])
    #循环遍历二维数组
    for i in range(n):
        for j in range(m):
            if cw(a[i][j]) % 2 != 0:
                c += 1
    print(c)
    
    • 1

    信息

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