题意
题意很简单呐,给出一串数字,算出其中互为2倍的数字有多少对。
技巧
利用选择排序的那种思想就能搞定这个
还有关于那个输出的那种结构需要自己动动脑子想一下
代码
#include <iostream>
using namespace std;
int num[20];
void func(int count){ //判断为2倍的数有多少对,输出对数
int total=0;
for(int i=0;i<count;i++){
for(int j=i+1;j<count;j++){
if(num[i]==2*num[j] || num[j] == 2*num[i]){
total++;
}
}
}
cout<<total<<endl;
}
int main()
{
int count = 0,temp;
while(cin>>temp){
if(temp==0){
func(count);
count=0;
}
if(temp==-1) break;
num[count] = temp;
count++;
}
return 0;
}
happy coding
欢迎一起来讨论~~~