思路分析:一个为插入栈,另一个为弹出栈,可以认为插入站提供入队列的功能,弹出栈提供出队列的功能。如果弹出栈不为空,则直接弹出它的数据。如果弹出栈为空,则依次弹出插入栈的数据,放入弹出栈中,再弹出它的数据。代码如下:#include "stdafx.h"#include #include using namespace std;template class QueueByDoubleStack{public: size_t size(); bool empty(); void push(T t); void pop(); T top();private: st... Read More
posted @ 2014-03-25 19:18 源子陌 Views(728) Comments(0) Diggs(0) Edit
思路分析:intisdigit(charc)函数用来判断字符c是否为数字,当c为数字0~9时,返回非零值,否则返回零。使用时需要包含头文件。如果一个字符为数字,那输出它减去48之后的整数形式,即为这个数的值。代码如下:#include "stdafx.h"#include #include int main(){ int c; while ((c = getchar()) != EOF) { getchar(); if (isdigit(c)) printf("是:%d\n", c-48); else ... Read More
posted @ 2014-03-25 11:41 源子陌 Views(430) Comments(0) Diggs(0) Edit
方法一:递(sangxin)归(bingkuang)法,遍历字符串,每个字符只能取或不取。取该字符的话,就把该字符放到结果字符串中,遍历完毕后,输出结果字符串。代码如下:#include "stdafx.h"#include #include void CombineRecursiveImpl(const char* str, char* begin, char* end){ if (*str == 0) { *end = 0; if (begin != end) printf("%s", begin); return... Read More
posted @ 2014-03-25 10:23 源子陌 Views(1931) Comments(0) Diggs(0) Edit