标签:
//no AC //思路就是,第一个数+最后一个数+中间数字(分奇数和偶数) #include "stdio.h" #define MAX 10 int main(void){ int i; int num; int sum; //求和 int score[MAX]; scanf("%d", &num); while(num != 0){ for(i=0; i<num; i++){ //动态赋值 scanf("%d", &score[i]); } for(i=0; i<num; i++){ if(num % 2 == 0){ sum = score[0] + score[num-1] + score[num/2] + score[num/2 - 1]; } else{ sum = score[0] + score[num-1] + score[num/2]; } } printf("%d\n", sum); sum = 0; } return 0; } */ /* * Result:Time Limit Exceeded */ //解题思路,就是除去最后一个数字,其余数字相加 #include "stdio.h" int main(void){ int i; int j; int num; int sum = 0; while(scanf("%d", &num), num){ //逗号后面的num,表示num的值,为0直接跳出循环。 for(i=0; i<num; i++){ scanf("%d", &j); sum += j; } printf("%d\n", sum); sum = 0; } return 0; } /* * Result:running */
标签:
原文地址:http://www.cnblogs.com/cnfanhua/p/4220890.html