173 条题解
-
-2ZR_VIJOS LV 6 @ 2017-06-02 10:52:38
#include<stdio.h>
#include<string.h>
int num[105] = { 0 };
int flag[105] = { 0 };
int check(int n,int checknum)
{
int i = 0;
for (i = 0; i < n; i++){
if (num[i] == checknum && flag[i]==0){
flag[i] = 1;
return 1;
}}
return 0;
}
int dealwith(int n)
{
int i = 0, j = 0;
int ans = 0;
for (i = 0; i < n; i++){
for (j = i + 1; j < n; j++){
if (check(n, num[i] + num[j]))
ans++;
}
}
return ans;
}
int main()
{
int n = 0;
int i = 0;freopen("data.in", "r", stdin);
scanf("%d", &n);
for (i = 0; i < n; i++)
{
scanf("%d ", &num[i]);
//printf("%d ", num[i]);
}
printf("%d\n", dealwith(n));return 0;
} -
-22017-05-18 17:04:06@
#include<iostream>
using namespace std;
int main()
{
int n,sum=0,t,b[1000];
n>=3&&n<=100;
cin>>n;
float a[n+1];
for(int i=1;i<=n;i++)
{a[i]>=0&&a[i]<=10000;cin>>a[i];}
for(int i=1;i<=n-1;i++)
for(int w=i+1;w<=n;w++)
if(a[i]>a[w])
{t=a[i];a[i]=a[w];a[w]=t;}
for(int i=n;i>=0;i--)
{for(int z=2;z<i;z++)
{for(int x=1;x<=z-1;x++)
if(a[z]+a[x]==a[i]){sum+=1;a[i]=0;}}}
cout<<sum<<endl;
return 0;
} -
-22017-05-13 23:05:16@
/* 排序后查找问题 Date:2017/5/12 */ #include<iostream> #include<stdlib.h> using namespace std; int compInc(const void*a, const void*b) { return *(int *)a-*(int *)b; } int main() { //n正整数个数, A[i] i<n保存整数 ,len:A的元素数,num总个数 int n,num=0; int A[100]; int len=100; //读入n cin>>n; //读入整数 for(int i=1;i<=n;i++)cin>>A[i]; //先排序 qsort(A,len,sizeof(A[0]),compInc); //求和并检查 for(int x=1;x<=n;x++) { for(int y=x+1;y<=n;y++) { for(int z=y+1;z<=n;z++) { if(A[x]+A[y]==A[z]) { num+=1; break; } } } } cout<<num; return 0; }
新手求助……想不通啊,为啥输出是零啊??干瞪眼一晚上
-
-22017-05-13 17:04:12@
#include <iostream>
using namespace std;bool ok(int);
int number = 0;
int data[100] = {0};
int has[100] = {0};
int result = 0;
int n = 0;int main()
{
cin>>number;
for (int i = 0; i<number; i++)
cin>>data[i];
for (int i = 0; i<number; i++)
for (int s = 0; s<number; s++)
for (int t = 0; t<number; t++)
if (data[i] == data[s] + data[t] && s != t && ok(data[i]))
{
has[n] = data[i];
result++;
n++;
}
cout<<result<<endl;
}bool ok(int b)
{
for(int a = 0; a<100; a++)
if(has[a] == b)
return false;
return true;
}//没啥难度,if语句原来判断没加s!=t
//数组初始化忘了用{}
//审题!数字个数不是组数!
//if== -
-22017-05-06 17:44:47@
#include <iostream>
#include <cstdio>
#include <string.h>
#include <cmath>
#include <algorithm>
using namespace std;
const int maxn = 105;
int a[maxn];
int b[maxn];
int main(){
int n;
scanf("%d",&n);
for(int i=0;i<n;i++){
scanf("%d",&a[i]);
}
memset(b,0,sizeof(b));
sort(a,a+n);
int cnt = 0;
for(int i=0;i<n-1;i++){
for(int j=i+1; j<n; j++){
for(int k=j+1; k<n ;k++){
if(a[i] + a[j] == a[k]&&!b[k]){
cnt++;
b[k] = 1;
}
}
}
}
cout<<cnt<<endl;
return 0;
} -
-22017-04-22 21:20:31@
#include<stdio.h> int main() { int a,b[101]; int i,j,k,q;//小参数 int sum=0; scanf("%d",&a); for(i=1;i<=a;i++) { scanf("%d",&b[i]); } for(i=1;i<=a;i++)//有几个数 { for(j=1;j<=a;j++)//循环数的个数 { q=0; for(k=j+1;k<=a;k++)//因为不能连自己,就是a-1次 { if(k!=i&&j!=i&&b[k]+b[j]==b[i]) { q=1; break;//跳出一层for循环 } } if(q==1) { sum++; break;//同上 } } } printf("%d",sum); }
-
-22017-04-12 13:53:12@
#include <iostream>
#define max 100
using namespace std ;int main ()
{
int a[max];
int n = 0 ;
cin >> n ;
for ( int i = 0 ; i < n ; i++ )
cin >> a[i];
int sum[max][max];
for ( int i = n-1 ; i > 0 ; i-- )
for ( int m = 0 ; m < i ; m++ )
{
sum[i][m] = a[i]+a[m];
}
int ans = 0 ;
for ( int i = 0 ; i < n ; i++ )
{
for ( int k = n-1 ; k > 0 ; k-- )
for ( int l = 0 ; l < k ; l++ )
if (a[i]==sum[k][l] )
{
i++;
k = n - 1 ;
l = 0 ;
ans++;
}
}
cout << ans;
return 0 ;
} -
-22017-03-27 13:38:21@
#include<cstdio>
#include<set>
#include<cstring>
#include<algorithm>
using namespace std;
int main()
{
int n,a[10001],vis[20002];
set<int> s;
scanf("%d",&n);
memset(vis,0,sizeof(vis));
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
vis[a[i]]=1;
}
for(int i=0;i<n-1;i++)
{
for(int j=i+1;j<n;j++)
{
int x=a[i]+a[j];
if(vis[x])
s.insert(x);
}
}
printf("%d\n",s.size());
return 0;
} -
-22017-02-21 21:26:09@
暴力过应该也行,不过我稍稍优化了一下。
先从小到大排序,然后从第三个数字开始判断,对于每一个数字,只要枚举它前面的某两个数之和即可,枚举也有优化,也就是两头开始。比如说a b c d e,判断e的顺序是a+d,b+d,c+d,a+c,b+c,a+b,一旦满足则退出,一旦大于e则把尾数向前来一个。
```c++
#include <iostream>
#include <algorithm>
#define MAX 110
using namespace std;
int num[MAX];int main(void)
{
int i,j,k,n,ans = 0;
cin>>n;for(i = 0;i < n;i++)
cin>>num[i];sort(num,num + n);
for(i = 2;i < n;i++){
for(j = i - 1;j > 0;j--){
for(k = 0;k < j;k++){
if(num[j] + num[k] == num[i]){
ans++;
j = 0;
break;
}
else if(num[j] + num[k] > num[i])
break;
}
}
}cout<<ans<<"\n";
return 0;
} -
-22017-02-15 15:52:28@
亲们,帮我看看哪里出问题了;
#include <stdio.h>
int main(int argc, char const *argv[])
{
int n,k=0;
int a[100];
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
for(int i=0;i<n;i++)
{
for(int j=0;j<n-1;j++)
{
for(int t=j+1;t<n;t++)
{
if(j!=i&&t!=i&&(a[i]==a[j]+a[t]))
{
k+=1;
break;
}
}
}
}
printf("%d\n",k);
return 0;
} -
-22017-02-07 15:03:52@
#include<iostream> using namespace std; int main() { int n; cin >> n; int a[900] = {}; int b[100000] = {}; //cout << a[1]; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i1 = 1; i1 < n; i1++) { for (int i2 = i1 + 1; i2 <= n; i2++) { if (a[i1] != a[i2]) { int temp = (a[i1] + a[i2]); b[temp] = 1; } } } int sum = 0; for (int i3 = 1; i3 <= n; i3++) { if (b[a[i3]]) sum += 1; } cout << sum << endl; //system("pause"); return 0; }
-
-22017-01-21 07:50:23@
var
n,i,j,k:integer;
a,b:array[1..101] of integer;
beginreadln(n);
fillchar(b,sizeof(b),0);
for i:=1 to n do
read(a[i]);
for i:=1 to n do
for j:=1 to n do
for k:=j+1 to n do
if a[i]=a[j]+a[k] then b[i]:=1;
k:=0;
for i:=1 to n do
if b[i]=1 then k:=k+1;
writeln(k);end.
-
-22016-08-11 11:50:32@
md这题目哪里坑了?
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<stdlib.h>
int n,num=0,x[109];
using namespace std;
int cmp(const void*a,const void*b)
{
return (int)a-*(int*)b;
}
int main(){
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>n;
for(int i=0;i<n;i++)
scanf("%d",&x[i]);
qsort(x,n,sizeof(x[0]),cmp);
for(int i=n-1;i>=0;i--)
for(int j=0;j<i-1;j++)
for(int z=j+1;z<i;z++)
{
if(x[z]+x[j]==x[i])
{num++;
x[i]=-2147483646;
}}
printf("%d",num);
return 0;
}
测试数据 #0: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #1: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #2: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #3: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #4: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #5: Accepted, time = 0 ms, mem = 556 KiB, score = 10
测试数据 #6: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #7: Accepted, time = 15 ms, mem = 556 KiB, score = 10
测试数据 #8: Accepted, time = 0 ms, mem = 560 KiB, score = 10
测试数据 #9: Accepted, time = 0 ms, mem = 556 KiB, score = 10
信息
- ID
- 1911
- 难度
- 6
- 分类
- (无)
- 标签
- 递交数
- 17097
- 已通过
- 4518
- 通过率
- 26%
- 被复制
- 28
- 上传者