google面试题
来源:互联网 发布:黑暗之光圣痕升阶数据 编辑:程序博客网 时间:2024/05/17 15:19
解:
#include <iostream>#include <stack>#include <windows.h>using namespace std;typedef struct node{int key;node*next;node(node*p, int m): next(p),key(m){};}*linklist,node;stack<int>liststack;class link{public:link(){n=0;}linklist build(node*m);void traverse(node*p);private:int n;};linklist link::build(node*m){ m->next=NULL; m->key=0;cout<<"please input the number n:"<<endl;cin>>n;linklist r=m;for(int i=0;i<n;i++){linklist p1=new node(NULL,0);int a;cout<<"please input the node:---"<<endl;cin>>a;liststack.push(a);p1->key=a;p1->next=m->next;r->next=p1;r=p1;}return r;}void link::traverse(node*p){int i=0;p=p->next;while(p!=NULL){linklist p0=p->next;int b=p0->key;cout<<"the---"<<i<<" --value is"<<b;cout<<endl;Sleep(400);liststack.push(b); p=p->next;i++;}}int main(){link mylink;linklist q=mylink.build(q);while(!liststack.empty()){ cout<<liststack.top(); liststack.pop(); } system("pause");return 0;}
题2:一场球赛,已知某队得了200分,且得分为3种可能:1分,2分,3分。
输出所有可能的情况。
#include<iostream>#include <windows.h>using namespace std;int a[]={};int find(int*a,int m,int sum,int n){ if(m<n) { if(m==n-1&&sum==0) for(int i=0;i<n;i++) { cout<<a[i]; } cout<<endl; if(sum>0) {m++; a[m]=0; find(a,m,sum-a[m],n); a[m]=1; find(a,m,sum-a[m],n); a[m]=2; find(a,m,sum-a[m],n); a[m]=3; find(a,m,sum-a[m],n);} }elsereturn 0;}int main(){ find(a,0,10,10); system("pause"); return 1;}
int main(){ find(a,0,10,201); system("pause"); return 1;}
- Google 面试题讨论
- 小小Google面试题
- google面试题
- 面试题2-- Google
- google面试题
- google面试题
- Google 的面试题
- Google面试题
- 一道Google面试题
- google 面试题 分享
- google面试题
- GOOGLE面试题
- Google面试题
- Google面试题
- google面试题
- google一些面试题
- google面试题搜集
- Google的面试题
- Oracle Job创建
- 设计模式:原型模式
- 冒泡排序和选择排序
- 我是特种兵2感悟
- LIST 去除并合并重复记录
- google面试题
- 榜样
- TFTP
- IOS中Json解析的四种方法
- JAVA与模式
- PC 上的 LVM 灾难修复
- 归并排序
- [转] C#.ToString()格式大全
- 图片剪掉中间部分,两边部分自动合并