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 |
Re:为什么总是WA啊,哪里错了?In Reply To:为什么总是WA啊,哪里错了? Posted by:BugKiller at 2008-03-17 22:12:42 算法错误。 例如temp=14时,if条件语句(temp%2==0||temp%3==0||temp%5==0)为真, 但实际上14不是ugly number。 > #include <stdio.h> > int main(){ > int ugly[1700]={0}; > int n,index=1,temp; > ugly[1]=1; > for(scanf("%d",&n);n>0;scanf("%d",&n)){ > temp=ugly[index]+1; > while(index<n){ > if(temp%2==0||temp%3==0||temp%5==0){ > index++; > ugly[index]=temp; > } > temp++; > } > printf("%d\n",ugly[n]); > } > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator