tyt_ @ 2024-10-15 20:19:26
50分哇!怎么做哇???
#include<bits/stdc++.h>
using namespace std;
int a[1005],cnt;
int main(){
int n;
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n-1;i++){
for(int j=i+1;j<=n;j++){
int x=a[i]+a[j];
for(int k=2;k<=sqrt(x);k++){
if(k*k==x){
cnt++;
break;
}
}
}
}
cout<<cnt;
return 0;
}
by SunXiaolang @ 2024-10-15 20:29:45
有没有一种可能,你cnt没有设0
by tyt_ @ 2024-10-15 20:32:41
@SunXiaolang 在主函数外面创建不写等于几就直接是0
by SunXiaolang @ 2024-10-15 20:34:58
#include<bits/stdc++.h>
using namespace std;
int a[1001];
int main()
{
int cnt=0,sum,n;
cin>>n;
for (int i=0;i<n;i++){
cin>>a[i];
}
for (int i=0;i<n;i++){
for (int j=i+1;j<n;j++){
sum=0;
sum+=a[i];
sum+=a[j];
if (floor (sqrt (sum))*floor (sqrt (sum))==sum) cnt++;
}
}
cout<<cnt;
}
热乎的ac代码(刚刚做的)
by SunXiaolang @ 2024-10-15 20:35:47
不要脸的求关
by tyt_ @ 2024-10-15 20:36:21
@SunXiaolang 栓Q
by kasayaki @ 2024-10-26 19:30:20
其实你这个把k=2改成k=0就AC了 因为0*0=0