- 博客(19)
- 收藏
- 关注
原创 C++求斐波那契数列的第n项
#include using namespace std;int fib(int n);int main(){ int a; while(cin>>a) { cout<<"the result: "<<fib(a)<<endl; } return 0;}int fib(int n){ if(n==1||n==2)
2016-08-24 16:06:40 9664
原创 100到1000之间有多少个数其各位数字之和是5
#include int main(){ int i, s, k, count = 0; for (i = 100; i < 1000; i++) { s = 0; k = i; while (k) { s += k % 10; k = k / 10; } if (s != 5) continue; else count++; } p
2015-11-01 21:16:35 19886 2
原创 约瑟夫环问题之选猴王
n只猴子围成一圈,顺时针方向从1到n编号。之后从1号开始沿着顺时针方向让猴子从1,2,3……,m依次报数,凡报到m的猴子都让其出圈,取消候选资格。然后不停的俺顺时针方向报数,让报到m的猴子出圈,最后剩下一个就是猴王。#include #include struct mon{ int num; struct mon * next;};struct mon * cre
2015-10-28 21:38:41 2431
原创 快速排序以及二分查找的实现
#include int BinSearch(int a[],int left,int right,int key);//声明二分查找void QuickSort(int a[],int left,int right);//声明快速排序int main(){ int a[101]; int i,n,key; printf("Please input total
2015-10-28 10:57:23 869
原创 编译原理词法分析程序
#include #include#include#include#includeusing namespace std;#define MAX 22char ch =' ';string key[15]={"switch","break","if","then","else","while","write","read","do", "int","const","char",
2014-06-12 09:21:02 10395 2
原创 06_05_词法分析
#include#include#include#define keywordSum 8//extern int TESTScan();char Scanin[300],Scanout[300]; //用于接收输入输出文件名FILE *fin,*fout;//用于指向输入输出文件的指针char *keyword[keywordSum]={ "if","else","for","
2014-06-05 09:39:56 1051
原创 顺序队列的基本操作
#include #include //#include #define MAXSIZE 100#define OK 1#define TRUE 1#define FALSE 0#define ERROR 0//using namespace std;typedef struct{ int data[MAXSIZE]; int front; //
2014-02-11 21:56:04 1017
原创 使用默认参数的构造函数
#include using namespace std;class Box{public: Box(int h=10,int w=10,int len=10); int volume();private: int height; int width; int length;};Box::Box(int h,int w,int len){
2013-11-01 17:16:08 537
原创 基于顺序栈的进制转换
#include #include #define M 10typedef struct //定义一个顺序栈{ int data[M]; int top;}SqStack;void InitStack(SqStack &st)//创建一个栈{ st.top=-1;}int PushStack(SqStack &st,
2013-10-09 09:36:12 1054
原创 C语言之大数相加
#include#includeint main(){ int f; int i,an,bn,k; char a[1000],b[1000]; int af[1000]={0},bf[1000]={0},c[1000]; while(scanf("%s%s",a,b)!=EOF) //输入字符串型的数字 { an=strlen(a); bn=strlen(b);
2013-09-13 17:34:49 764
原创 输入一个年输出其天干地支纪年法的表达式
#include #include using namespace std;char *day_name1(int x){ static char *name[20]={"Gui","Jia", "Yi", "Bing", "Ding", "Wu", "Ji", "Geng", "Xin", "Ren", "Gui"}; return (name[x]);}char *day_n
2013-08-24 11:23:54 1277
原创 队列的链式存储及其基本运算
#include #include #define QueueSize 10typedef struct Qnode //链队列的定义{ char data; struct Qnode *next;}Qtype; //链队中节点类型typedef struct qptr{ Qtype *front,*rear; //链队
2013-08-15 15:42:14 648
原创 队列的顺序存储及其基本操作
#include #include #define QueueSize 10typedef struct{ char data [QueueSize]; int front,rear;}SqQueue;void InitQueue(SqQueue &qu) //初始化队列{ qu.rear=qu.front=0;}int EnQueue(SqQue
2013-08-15 09:57:55 788
原创 栈的顺序存储及其基本操作
#include #include #define M 10typedef struct //定义一个顺序栈{ char data[M]; int top;}SqStack;void InitStack(SqStack &st)//创建一个栈{ st.top=-1;}int PushStack(SqStack &st, char x)//进栈操作
2013-08-14 11:13:21 1655
原创 栈的链式存储及其基本运算
#include #include #define M 10typedef struct stnode{ char data; struct stnode *next;}LinkStack;void InitStack(LinkStack *&ls) //初始化栈{ ls=NULL;}void PushStack(LinkStack *&ls,ch
2013-08-14 10:56:37 498
原创 对结构体中的数据进行排序
#include #include const int S=51000;using namespace std;struct TT{ int id,v1,v2;}f[S];bool cmp1(const TT &a, const TT &b)//按照结构体元素v1进行排序{ return (a.v1>b.v1);}bool cmp2(const TT &a, c
2013-08-10 15:54:14 3040
原创 整数各位数分离(C语言代码)
#includeint main(){ int m=1,i=0; long int n; int a[16]; printf("Input an integer: "); scanf("%ld",&n); if(n<0) { n=-n; printf("- "); } while(n/m!=0) { a[i]=(n/m)%10; m=m*10; i++;
2013-08-10 11:10:48 4933 1
原创 链表的逆置,归并,拆分以及其他函数集合
#include #include struct node{ int data; struct node *next;};struct node * creat1(int n)//逆序建立链表{ struct node *head,*p; int i; head=(struct node *)malloc(sizeof(struct node)
2013-08-10 11:07:56 752
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人