思路,跳过一个数
#include<stdio.h>
#include<assert.h>
void sumoffour(int a[], int n, int sum);
int main()
{
int a[100];
int T;
int n;
int sum;
scanf("%d", &T);
while(T--) {
printf("第%d组\n", T + 1);
scanf("%d%d", &n, &sum);
assert(n <= sizeof(a));
for(int i = 0; i < n && a[i] != EOF; i++) {
scanf("%d", &a[i]);
}
sumoffour(a, n, sum);
}
return 0;
}
void sumoffour(int a[], int n, int sum){
int i,j,c;
int m = n - 1;
int b[100];
int bs;
int number,A = 0;
for(i = 0; i < n && a[i] != EOF; i++){
number = 0;
bs = 0;
for(j = 0; j < n; j++){
if(j == i)
continue;
else{
number += a[j];
b[bs] = a[j];
++bs;
}
}
if(number == sum){
A = 1;
printf("The sum of ");
for(bs = 0; bs < n-1 && b[bs] != EOF;++bs)
printf("%d ", b[bs]);
printf("is %d\n", sum);
}
}
if(A == 0)
printf("No answer\n");
}
input形式
x //计算几组数据
y z//y是n-1个数 z是n-1个数的和
。。。。。。。//这里放上n个数
如此反复,共x次