Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
我就一悲剧啊……for循环里控制语句少写了个等于,WA了一次(附代码+思路)#include <iostream> using namespace std; int a[20]; int b[20]; int main() { freopen("in.txt","r",stdin); int n; while(scanf("%d",&n)&&n!=-1) { int m,sum=0; int i=1,j,p,q; a[1]=n; while(scanf("%d",&m)&&m!=0) a[++i]=m; for(j=1;j<=i;j++) b[j]=2*a[j]; for(p=1;p<=i;p++) for(q=1;q<=i;q++) if(a[p]==b[q]) sum=sum+1; printf("%d\n",sum); } return 0; } 我什么都没用,就用两个数组,b用来存放a的两倍,然后比较a,b数组相同元素的个数,输出就行,看到有些仁兄还用了sort,觉得好像没有必要…… 虽然暴力了,但是还是0MS,总觉得POJ上的时间有点问题………… Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator