5 条题解

  • 2
    @ 2025-9-20 15:55:59

    C语言解法 (数组运用,for循环中continue和break的使用)(新手求赞)

    #include <stdio.h>
    int main() {
        int n;
        scanf("%d", &n);
        int a[100];  
    
        for (int i = 0; i < n; i++) {
            scanf("%d", &a[i]);
        }
    
        int count = 0;
    
        for (int j = 0; j < n; j++) {
            int found = 0;
            for (int k = 0; k < n; k++) {
                if (k == j) continue; 
                for (int m = 0; m < n; m++) {
                    if (m == j || m == k) continue; 
                    if (a[j] == a[k] + a[m]) {
                        count++;
                        found = 1;
                        break;
                    }
                }
                if (found) break;
            }
        }
    
        printf("%d\n", count);
    
        return 0;
    }
    

    信息

    ID
    6189
    时间
    1000ms
    内存
    125MiB
    难度
    3
    标签
    递交数
    702
    已通过
    254
    上传者