十六:二叉树遍历
这算是比较老的一道题了,如果是做题,可以直接画图画出来,以前写过已知二叉树前序中序求后序的代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#include #include using namespace std; struct { struct *left; struct *right; char num; }; typedef struct treenode; void getit(char* inor,char* preor,int length){ if(0==length) return; Tree * newnode = new Tree; newnode->num=*preor; int flag=0; for(;flagnum; return; } int main(){ char* preor="DBACEGF"; char* inor="ABCDEFG"; getit(inor,preor,8); printf("n"); return 0;
}
|
十七:约瑟夫环
也是一道十分经典的问题,是属于约瑟夫环好人与坏人问题之前打过表
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#include using namespace std;
int num[20]={0}; bool check(int k,int m){ int n=2*k,s=0,resq; int i; for(i=1;i<=k;i++){ resq=n-i+1; s=(s+m-1)%resq; if(s
|
十八:双基回文数
也是老题了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
def check(n): count=0 a=str(n) b=a[::-1] if a==b: return True else: return False
if __name__=='__main__': n=1600000 while True: n+=1 if check(n): print n exit()
|
近期评论