摘要:方法一:利用构造函数和静态数据成员[cpp]view plaincopy#include<iostream>usingnamespacestd;classTemp{public:Temp(){++N;Sum+=N;}staticvoidReset(){N=0;Sum=0;}staticintGetSum(){returnSum;}private:staticintN;staticintSum;};intTemp::N=0;intTemp::Sum=0;intsolution_Sum(intn){Temp::Reset();Temp*a=newTemp[n];delete[]a;a=
阅读全文
摘要:#include <stdio.h>#include <stdlib.h>typedef struct node{ int data; node *lchild; node *rchild;}TreeNode;void InsertNode(TreeNode *&Node, int n){ if (Node == NULL) { Node = (TreeNode*)malloc(sizeof(TreeNode)); Node->data = n; Node->lchild = Node->rchild = NULL; } else { if (
阅读全文
摘要:#include <stdio.h>void DFS(int arr[], int n, int visited[], int result[], int row){ if (row >= n) { for (int i = 0; i < n; i++) { printf("%d ", result[i]); } printf("\n"); return; } for (int i = 0; i < n; i++) { if (visited[i] == 0) { visited[i] = 1; result[row] =
阅读全文
摘要:赋值了吗?Time Limit:1000MSMemory Limit:65535KBSubmissions:170Accepted:48Description现在很多的程序设计语言中,赋值已经是一个不容忽视的问题,如果一个变量在未进行赋值的情况下使用,那么这个值将是不定的(哈哈,我已经被遭了好多次了)!而我写的程序用到的变量实在是太多了,又不想自己统计哪些变量是已经赋值了的,现在就请你帮我统计一下哪些变量已经赋值了。为了简化问题,我们假设最开始仅有变量a中有确定的值。变量为单个小写字母,每行恰好有三个字符,中间一个是赋值运算符'='。请编程求出含N行的程序段运行以后有哪些变量中
阅读全文
摘要:#include <stdio.h>#include <stdlib.h>typedef struct node{ char data; node *lchild; node *rchild;}TreeNode;void CreateTree(TreeNode *&Node, char *pstr){ int top = -1; TreeNode *Stack[100]; char ch = *pstr; int j = 0; int t; TreeNode *p = NULL; while(ch != '\0') { switch(ch) {
阅读全文
摘要:个人的一个作品,实现了局域网的聊天,采用MFC多文档多视图编写,主要功能如下:文字聊天,文件传送,QQ表情,魔法表情,屏幕截图,滚动字幕,抖动窗口,运行效果如下:百度网盘下载地址:http://pan.baidu.com/s/1jGjbVim
阅读全文
摘要:#include <stdio.h>typedef struct{ int x; int y; int pre;}Queue;Queue Qu[1000];int Map[20][20];int front, rear;int M, N;int aim[4][2] = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};void Print(int front){ int j, k; j = k = front; j = front; while(j != 0) { j = Qu[k].pre; Qu[k].pre = -1...
阅读全文
摘要:单链表排序算法,代码如下:#include <stdio.h>#include <stdlib.h>typedef struct Node{ int data; Node *next;}LinkList;void CreateLinkList(LinkList *pHeader, int nLen, int *arr){ pHeader->next = NULL; LinkList *p; p = pHeader; for (int i = 0; i < nLen; i++) { LinkList *node = (LinkList*)malloc(...
阅读全文