珠心算测验(ACM)

2017-11-10 20:28:49来源:CSDN作者:Duke10人点击

分享

这里写图片描述

这里写图片描述


python3做法:

n = int(input())lst= list(map(int,input().split()))times = []for i in lst:    for j in lst:        if i < j and i + j in lst and i+j not in times:            times.append(i+j)print(len(times))

c语言做法

#include<stdio.h>int main(){    int n, i, j, k, count = 0, temp;    scanf("%d", &n);    int a[101] = {0};    int b[101] = {0};    for (i = 0; i < n; i++) //输入    {        scanf("%d", &a[i]);        b[i] = a[i];    }    for (i = 0; i < n - 1; i++) //排序    {        for (j = 0; j < n - 1 - i; j++)        {            if (a[j] > a[j + 1])            {                temp = a[j];                a[j] = a[j + 1];                a[j + 1] = temp;            }        }    }       for (i = 0; i < n; i++)    {        for (j = i + 1; j < n; j++)        {            temp = a[i] + a[j];            for (k = 0; k < n; k++)            {                if (temp == b[k])                {                    count++;                    b[k] = 0;                    continue;                }            }        }    }    printf("%d/n", count);    return 0;}

相关文章

    无相关信息

最新文章

123

最新摄影

微信扫一扫

第七城市微信公众平台