POJ.1552 Doubles(水)
题意分析
暴力
代码总览
#include <cstdio>
#include <stdio.h>
#define nmax 100
using namespace std;
int a[nmax];
int n;
int main()
{
//freopen("in.txt","r",stdin);
while(true){
int t;
scanf("%d",&t);
if(t == -1) break;
if(t == 0){
printf("0\n");
continue;
}else{
int cnt = 0;
a[cnt++] =t;
while(scanf("%d",&t) && t!= 0){
a[cnt++] = t;
}
int ans = 0;
for(int i = 0; i<cnt;++i){
for(int j = 0; j<cnt;++j){
if(i == j) continue;
else{
if(a[j] == 2* a[i]) ans++;
}
}
}
printf("%d\n",ans);
}
}
return 0;
}
本文提供了一种解决POJ.1552Doubles问题的简单直接的方法,通过双重循环遍历数组来寻找两倍关系的元素对。此题主要考察基本的数组操作和循环结构。
1621

被折叠的 条评论
为什么被折叠?



