代码改变世界

随笔分类 -  C++

Parentheses Column Values

2015-07-08 16:10 by kingshow, 304 阅读, 收藏, 编辑
摘要: Parentheses Column ValuesBetween the columns using four parentheses ‘(‘, ‘)’, ‘[‘, ‘]’, a correct parentheses column is defined as below:1. ‘()’ or ‘[... 阅读全文

Chess

2015-05-27 17:16 by kingshow, 2076 阅读, 收藏, 编辑
摘要: There is a mobile piece and a stationary piece on the N×M chessboard. The available moves of the mobile piece are the same as set out in the image bel... 阅读全文

Laughing Bomb

2015-05-27 16:20 by kingshow, 3050 阅读, 收藏, 编辑
摘要: You are busy to promote a newly released film in a movie theater. The title is ‘Biochemical Laughing Bomb’ which is about terror.Guerrillas drop a bio... 阅读全文

Work Conversion

2015-05-27 12:05 by kingshow, 323 阅读, 收藏, 编辑
摘要: Most work in a factory is performed by robots. In the robots’ work, the most time used is when converting an operation. Therefore, if you design an au... 阅读全文

C++语言,统计一篇英文文章中的单词数(用正则表达式实现)

2013-11-05 16:18 by kingshow, 1786 阅读, 收藏, 编辑
摘要: 下面的例子展示了如何在C++11中,利用regex_search()统计一篇英文文章中的单词数:#include #include #include #include using namespace std;// 统计单词数int countword(string& str){ try { int n = 0; smatch m; // 保存匹配结果的match_result // 匹配单词的正则表达式, // 包含了大小写英文字母,连字符,括号,引号 // ... 阅读全文

C++实现另一个猜数字游戏

2013-10-31 12:12 by kingshow, 2069 阅读, 收藏, 编辑
摘要: 在 C语言实现一个简单的猜数字游戏 中,我们用C语言实现了一个简单的猜数字游戏,但是整个逻辑都在main()函数中,这种一个main函数从头到尾的方式很不好,今天我们用C++来将这个程序改写一下。 整个程序的大部分工作,实际上是由主持人这个角色完成的,包括确定最初的目标数字,判断猜测的数字大小,因此,我们可以将主持人抽象成Judge这个类,让这个类来负责这些工作,而主函数则负责与之交互,完成游戏过程。#include #include using namespace std; class Judge{public: Judge() { max = 100; ... 阅读全文