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 |
我想用递归来解,感觉思路很有意思,可惜不知道哪里出错了哦~~请大侠们帮帮忙(附代码)#include<iostream.h> #include<string.h> #include <stdio.h> #include<math.h> int i,t,temp,a; int test(int k) { if(k==0) return 0; else { a=test(k-1); t=a-k; if(t>0) { temp=1; for(i=0;i<k;i++) { if(test(i)==t) { temp=0; break; } } if(temp==1) return t; } else return test(k-1)+k; } } int main() { int num,k; while(cin>>k) { if(k==-1) return 1; num=test(k); cout<<num<<endl; } return 1; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator