上一页 1 2 3 4 5 6 7 8 9 10 ··· 12 下一页
摘要: 题目:请使用代码计算1234567891011121314151617181920*2019181716151413121110987654321。答:#include "stdafx.h"#include <iostream>#include <string>using namespace std;int _tmain(int argc, _TCHAR* argv[]){ string strOne; string strTwo; cout<<"输入第一个乘数:"; cin>>strOne; cout&l 阅读全文
posted @ 2012-09-04 19:15 venow 阅读(760) 评论(2) 推荐(0)
摘要: 题目:将字符串原地压缩,比如"eeeeeaaaff"压缩为 "e5a3f2"。答:#include "stdafx.h"#include <iostream>using namespace std;//字符串原地压缩void CompressString(char *str){ if (NULL == str) { return; } int count = 0; char *newStr = str; char ch = *str; while (*str != '\0') { if (*str != c 阅读全文
posted @ 2012-09-03 22:27 venow 阅读(2474) 评论(1) 推荐(1)
摘要: 题目:给定两个字符串s1和s2,要求判定s2是否能够被s1做循环移位得到的字符串包含。例如,给定s1=AABCD和s2=CDAA,返回true;给定s1=ABCD和s2=ACBD,返回false。答:#include "stdafx.h"#include <iostream>using namespace std;//获取next数组的值void GetNext(const char* pattern, int length, int *next){ int i = 0; next[i] = -1; int j = -1; while (i < lengt 阅读全文
posted @ 2012-09-03 20:30 venow 阅读(329) 评论(0) 推荐(0)
摘要: 题目:已知一个字符串,比如asderwsde,寻找其中的一个子字符串比如sde的个数,如果没有返回0,有的话返回子字符串的个数。答:#include "stdafx.h"#include <iostream>using namespace std;//获取next数组的值void GetNext(const char* pattern, int length, int *next){ int i = 0; next[i] = -1; int j = -1; while (i < length - 1) { if (-1 == j || pattern... 阅读全文
posted @ 2012-09-03 20:17 venow 阅读(1790) 评论(0) 推荐(0)
摘要: #include "stdafx.h"#include <iostream>using namespace std;//获取next数组的值void GetNext(const char* pattern, int length, int *next){ int i = 0; next[i] = -1; int j = -1; while (i < length - 1) { if (-1 == j || pattern[i] == pattern[j]) { i++; j++; ... 阅读全文
posted @ 2012-09-03 19:29 venow 阅读(531) 评论(0) 推荐(0)
摘要: 题目:给定一棵二叉树,要求按分层遍历该二叉树,即从上到下按层次访问该二叉树(每一层将单独输出一行),每一层要求访问的顺序从左到右。答:#include "stdafx.h"#include <fstream>#include <iostream>#include <vector>using namespace std;struct TreeNode { int m_nValue; TreeNode *m_pLeft; TreeNode *m_pRight;};//假定所创建的二叉树如下图所示/* ... 阅读全文
posted @ 2012-09-02 17:09 venow 阅读(5122) 评论(0) 推荐(0)
摘要: 题目:类CMyString的声明如下,请实现其赋值运算符的重载函数,要求异常安全,即当对一个对象进行赋值时发生异常,对象的状态不能改变。class CMyString{public: CMyString(char* pData = NULL); CMyString(const CMyString& str); CMyString& operator = (const CMyString& str); ~CMyString();private: char* m_pData;};答://1、可能有异常CMyString& CMyString::operator = 阅读全文
posted @ 2012-09-01 17:36 venow 阅读(547) 评论(0) 推荐(0)
摘要: 题目:输入一个正整数数组,将它们连接起来排成一个数,输出能排出的所有数字中最小的一个。举例:输入数组{32, 321},则输出这两个能排成的最小数字32132。请给出解决问题的算法,并证明该算法。答:算法如下,证明略。答:#include "stdafx.h"#include <iostream>#include <string>#include <sstream>using namespace std;//把int转化为stringstring int2str(int i) { string s; stringstream ss(s); 阅读全文
posted @ 2012-09-01 16:43 venow 阅读(728) 评论(0) 推荐(0)
摘要: 题目:把一个有序整数数组放到二叉树。答:#include "stdafx.h"#include <iostream>using namespace std;struct TreeNode { int m_nValue; TreeNode *m_pLeft; TreeNode *m_pRight;};//把一个有序整数数组放到二叉树void RecurCreateTree(int *p, int length, TreeNode *&pHead){ if (length > 0) { pHead = new TreeNode; int m... 阅读全文
posted @ 2012-08-31 22:59 venow 阅读(3910) 评论(0) 推荐(0)
摘要: 题目:从扑克牌中随机抽5张牌,判断是不是一个顺子,即这5张牌是不是连续的。2-10为数字本身,A为1,J为11,Q为12,K为13,而大小王可以看成任意数字。答:#include "stdafx.h"#include <iostream>#include <ctime>using namespace std;#define MAXVALUE 10000#define MINVALUE -1#define SIZE 14 #define NUMBER 5//扑克牌的顺子bool IsSort(int arr[], int length){ int pl 阅读全文
posted @ 2012-08-31 20:05 venow 阅读(1699) 评论(0) 推荐(0)
上一页 1 2 3 4 5 6 7 8 9 10 ··· 12 下一页