摘要: 转载的:http://www.cnblogs.com/qyaizs/articles/2039101.html分三块来讲述: 1 首先://注意在C和C++里不同 在C中定义一个结构体类型要用typedef: typedef struct Student { int a; }Stu; 于是在声明变量的时候就可:Stu stu1;(如果没有typedef就必须用struct Student stu1;来声明) 这里的Stu实际上就是struct Student的别名。Stu==struct Student 另外这里也可以不写Student(于是也... 阅读全文
posted @ 2014-02-08 11:59 CrazyCode. 阅读(190) 评论(0) 推荐(0)
摘要: 输入数字n,按顺序从打印出从1到最大的n位十进制数.比如输入3,也就是最大的3位数是999,那么就打印1.2.3.---999;方法1:非递归 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 void PrintNumber(char* number) 6 { 7 bool isBeginning0 = true; 8 int nLength = strlen(number); 9 for(int i = 0;i=0;i--){27 int nSum = num... 阅读全文
posted @ 2014-01-21 09:00 CrazyCode. 阅读(241) 评论(0) 推荐(0)
摘要: 数据大小是在一个范围内的,可以使用常量大小的辅助空间.不得超过O(n); 1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 void SortAges(int ages[],int length) 8 { 9 if(ages==NULL||lengtholdestAge)20 throw new std::exception("age out of range.");21 ++timesOfAge[age];22 }23 ... 阅读全文
posted @ 2014-01-20 10:24 CrazyCode. 阅读(277) 评论(0) 推荐(0)
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 #include 5 using namespace std; 6 7 8 void swap(int* a ,int *b) 9 {10 int temp = *a;11 *a=*b;12 *b=temp;13 }14 int Partition(int data[],int length,int start,int end)15 {16 if(data==NULL||length=length)17 throw new std::excepti... 阅读全文
posted @ 2014-01-20 09:51 CrazyCode. 阅读(146) 评论(0) 推荐(0)
摘要: 1 void RemoveNode(ListNode** pHead,int value) 2 { 3 if(pHead==NULL||*pHead==NULL) 4 return; 5 ListNode* pToBeDeleted = NULL; 6 if((*pHead)->m_nValue==value) 7 { 8 pToBeDeleted=*pHead; 9 *pHead=(*pHead)->m_pNext;10 }11 else12 {13 ListNode* ... 阅读全文
posted @ 2014-01-19 11:50 CrazyCode. 阅读(215) 评论(0) 推荐(0)
摘要: 1 #include "stdafx.h" 2 #include 3 4 using namespace std; 5 struct ListNode 6 { 7 int m_nValue; 8 ListNode* m_pNext; 9 };10 11 void AddToTail(ListNode** pHead,int value)12 {13 ListNode* pNew=new ListNode();14 pNew->m_nValue=value;15 pNew->m_pNext=NULL;16 if(pHead==NULL)17 ... 阅读全文
posted @ 2014-01-19 11:49 CrazyCode. 阅读(1189) 评论(0) 推荐(0)
摘要: 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 const int MaxNum=9; 6 int iArr[MaxNum];//定义数组 7 void print(int cur,int n); 8 inline void Swap(int *a,int *b)//交换两个位置的值 9 {10 int temp;11 temp=*a;12 *a=*b;13 *b=temp;14 }15 int _tmain(int argc, _TCHAR* argv[])16 {17... 阅读全文
posted @ 2014-01-16 13:28 CrazyCode. 阅读(257) 评论(0) 推荐(0)
摘要: 样例输入:DBACEGF ABCDEFG 输出:ACBFGEDBCAD CBAD 输出:CDAB 1 #include "stdafx.h" 2 #include 3 #include 4 using namespace std; 5 void show(int n,string lhs,string rhs); 6 int _tmain(int argc, _TCHAR* argv[]) 7 { 8 string s1 = "DBACEGF",s2="ABCDEFG"; 9 int n=s1.size();10 show(n,s1, 阅读全文
posted @ 2014-01-15 11:14 CrazyCode. 阅读(377) 评论(0) 推荐(0)
摘要: 输入一个数字n;和一个出栈序列.入栈顺序是从1-n看是否可行..如n=5,出栈序列是1 2 3 4 5,这个可行输出YES 如出栈序列是 5 4 1 2 3 则输出NO#include "stdafx.h"#include#includeusing namespace std;const int MAXN=1000+10;int n,target[MAXN];int _tmain(int argc, _TCHAR* argv[]){ cin>>n; stack s; int A=1,B=1; for(int i =1;i>target[i]; int ok 阅读全文
posted @ 2014-01-14 22:50 CrazyCode. 阅读(145) 评论(0) 推荐(0)
摘要: 卡片游戏桌面上有一叠牌,从第一张牌开始从上往下一次编号为1-n.当至少还剩下两张牌时进行一下操作:把第一张牌扔掉,然后把新的第一张放到整叠牌的最后。输入n,输出每次扔掉的牌,以及最后剩下的牌。样例输入:7样例输出:1 3 5 7 4 2 6 1 #include "stdafx.h" 2 #include 3 using namespace std; 4 5 int _tmain(int argc, _TCHAR* argv[]) 6 { 7 int num[100]; 8 int inputNum; 9 cin>>inputNum;10 for(int i = 阅读全文
posted @ 2014-01-14 22:09 CrazyCode. 阅读(252) 评论(0) 推荐(0)