cout

算法习题---5-3卡牌游戏(UVa10935)

与世无争的帅哥 提交于 2019-11-29 23:32:29
一:题目 给定n张卡片,按照1-n的顺序编号,然后拿出一张卡片扔掉,拿出一张卡片放到最后,重复该操作直到只剩1张卡片。 求扔掉的卡片序列和最后剩的卡片的编号。 (一)样例输入 7        //卡牌编号从1到7 19       //卡牌编号从1到19 10 6 0 (二)样例输出 Discarded cards: 1, 3, 5, 7, 4, 2 Remaining card:6 Discarded cards: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 4, 8, 12, 16, 2, 10, 18, 14 Remaining card:6 Discarded cards: 1, 3, 5, 7, 9, 2, 6, 10, 8 Remaining card:4 Discarded cards: 1, 3, 5, 2, 6 Remaining card:4 二:代码实现 #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <queue> using namespace std; #define MAX_N 15 int main103() { freopen("data5_3_h.in", "r", stdin); freopen("data5_3_h.out", "w",

第一次编程作业

走远了吗. 提交于 2019-11-29 22:11:17
github PSP2.1 Personal Software Process Stages 预估耗时(分钟) 实际耗时(分钟) Planning 计划 :明确需求和其他因素,估计以下任务需要多少时间 30 30 Estimate 估计这个任务需要多少时间 900 10 Development 开发 (包含下面8个子任务) 预估值 实际值 Analysis 需求分析(包括学习新技术) 120 500 Design Spec 生成设计文档 10 10 Design Review 设计复审 5 5 Coding Standard 代码规范(为开发制定合适的规范) 10 10 Design 具体设计(用伪代码,流程图等方法来设计具体模块) 60 30 Coding 具体编码 300 360 Code Review 代码复审 60 30 Test 测试(自我测试,修改,提交修改) 60 90 Reporting 报告 Test Report 测试报告 10 20 Size Measurement 计算工作量 10 10 Postmortem & Process Improvement Plan 事后总结并提出过程改进计划 30 300 合计 715 1115 解题思路 1.首先根据“!”来将该条输入的难度提取出来,再删去“num!”。 2.再根据“,”来将姓名提取出来,再删去“name,”

STL string 常见用法详解

南笙酒味 提交于 2019-11-29 22:02:17
《算法笔记》中摘取 string 常见用法详解 1. string 的定义 //定义string的方式跟基本数据类型相同,只需要在string后跟上变量名即可 string str; //如果要初始化,可以直接给string类型的变量进行赋值 string str = "abcd"; 2. string 中内容的访问 (1) 通过下标访问 //一般来说,可以直接像字符数组那样去访问string #include <stdio.h> #include <string> using namespace std; int main() { string str = "abcd"; for(int i = 0; i < str.length(); i++) { printf("%c ", str[i]); //输出abcd } return 0; } //如果要读入和输出整个字符串,则只能用 cin 和 cout #include <iostream> #include <string> using namespace std; int main() { strng str; cin >> str; cout << str; return 0; } //使用printf来输出string //即用c_str()将stringelixir转换为字符数组进行输出 #include <stdio

How do I use for_each to output to cout?

删除回忆录丶 提交于 2019-11-29 21:49:59
Is there a more straight-forward way to do this? for_each(v_Numbers.begin(), v_Numbers.end(), bind1st(operator<<, cout)); Without an explicit for loop, if possible. EDIT: How to do this for std::cin with a std::vector if possible? (How to read n elements only)? Björn Pollex You could achieve this using std::copy into a std::ostream_iterator : std::vector<int> v_Numbers; // suppose this is the type // put numbers in std::copy(v_Numbers.begin(), v_Numbers.end(), std::ostream_iterator<int>(cout)); It would be even nicer if you add some suffix: std::copy(v_Numbers.begin(), v_Numbers.end(), std:

编译原理 词法分析实验

血红的双手。 提交于 2019-11-29 20:34:35
实验一:词法分析 一、实验目的 通过设计编制调试一个具体的词法分析程序,加深对词法分析原理的理解。并掌握在对程序设计语言源程序进行扫描过程中将其分解为各类单词的词法分析方法。 编制一个读单词过程,从输入的源程序中,识别出各个具有独立意义的单词,即基本保留字、标识符、常数、运算符、分隔符五大类。并依次输出各个单词的内部编码及单词符号自身值。 二、实验预习提示 1、 词法分析器的功能和输出格式 词法分析器的功能是输入源程序,输出单词符号。词法分析器的单词符号常常表示成以下的二元式(单词种别码,单词符号的属性值)。本实验中,采用的是一类符号一种别码的方式。 2、 单词的BNF表示 <标识符>----> <字母><字母数字串> <无符号整数>----> <数字><数字串> <加法运算符>----> + <减法运算符>----> - 等等 3、 模块结构(见课本P95-96)(可根据自己的理解适当修改) 三、实验过程和指导: (一) 准备: 阅读课本有关章节,明确语言的语法,写出基本保留字、标识符、常数、运算符、分隔符和程序例。 初步编制好程序。 准备好多组测试数据。 (二) 上机: (三) 程序要求: 1. 要求用C++Builder或者Dephi或者VB或者VC或者JAVA等可视化编程工具编写;要求有界面(即一般windows下应用程序界面)。 2. 输入为某语言源代码。 程序输入

PAT乙级1010.一元多项式求导(25)

混江龙づ霸主 提交于 2019-11-29 19:31:50
1010 一元多项式求导 (25)(25 分) 设计函数求一元多项式的导数。(注:x^n^(n为整数)的一阶导数为n*x^n-1^。) 输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。 输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。 输入样例: 3 4 -5 2 6 1 -2 0 输出样例: 12 3 -10 1 6 0 分析:在输入时即可,处理出结果,先进先出,使用队列存储结果,常数项求导后,为0,需做特殊处理 #include<iostream> #include<queue> #include<stdlib.h> using namespace std; struct M { int x;//系数 int y;//指数 }; int main() { queue<M> Q;//存储求导后的结果 int m, n; while (cin >> m >> n) { if (n != 0) { m = m * n; n--; M *a = new M(); a->x = m; a->y = n; Q.push(*a); } } if(Q.size() == 0) cout << 0 << " " << 0;

【杂谈opencv】OpenCV中的cvRound()、cvFloor()、 cvCeil()函数讲解

泪湿孤枕 提交于 2019-11-29 19:18:30
功能:cvRound(), cvFloor(), cvCeil()函数讲解。 函数cvRound,cvFloor,cvCeil 都是用一种舍入的方法将输入浮点数转换成整数: cvRound():返回跟参数最接近的整数值,即四舍五入; cvFloor():返回不大于参数的最大整数值,即向下取整; cvCeil():返回不小于参数的最小整数值,即向上取整; ===============分割线=============== 代码演示 //---------------------------------------------------------- //功能:cvRound(), cvFloor(), cvCeil()函数讲解。 // cvRound():返回跟参数最接近的整数值,即四舍五入; // cvFloor():返回不大于参数的最大整数值,即向下取整; // cvCeil():返回不小于参数的最小整数值,即向上取整; //---------------------------------------------------------- #include <opencv2/opencv.hpp> using namespace std; int main() { //--------------【正数部分】--------------------------------

003 :FileStorage以及Mat类的使用

元气小坏坏 提交于 2019-11-29 19:11:26
1.FileStorage类是一个XML/YAML、JSON 文件存储类,用于包含所需读或者写的文件信息 ,在进行计算时候可以用这样的方式保存结果,以便于后面进行检索。 2. Mat::eye(Height,width,Dtype)创建单位举证 ,Mat::ones(Height,width,Dtype)创建元素全部为1的举证,Mat::zeros(Height,width,Dtype)创建元素为0的矩阵。 3.矩形的相乘,以及与标量相乘的方式,举证的转置以及求逆举 1 #include "opencv2/opencv.hpp" 2 #include<string> 3 #include<iostream> 4 using namespace cv; 5 using namespace std; 6 7 int main(int, char** argv) 8 { 9 10 //FileStorage类是一个XML/Yaml、JSON 文件存储类,用于包含所需读或者写的文件信息 11 FileStorage fs("test.yml", FileStorage::WRITE); 12 // Save an int 13 14 int fps= 5; 15 fs << "fps" << fps; 16 // Mat::eye创建指定类型和大小的单位矩阵 17 Mat m1= Mat:

unexpected output in cout and printf [duplicate]

只愿长相守 提交于 2019-11-29 18:05:24
Possible Duplicate: Could anyone explain these undefined behaviors (i = i++ + ++i , i = i++, etc…) For the code below: main() { int i = 1 ; cout << i << ++i << i++ ; } Why do I get the output as 331 instead of what was expected i.e 122 ? ( Same is the case even if I use printf instead of cout ?) << is a function, namely something like ostream& operator<<(ostream& lhs, RhsType rhs) . cout << a; is equivalent to operator<<(cout, a); The function returns lhs, that is return lhs , - so in the above examples cout is returned. So your example cout << i << ++i << i++ ; is equivalent to operator<<

C++ standard output format

瘦欲@ 提交于 2019-11-29 17:56:40
I want to create a C++ console application that print some text to different parts of the console. For example in QBasic you can use: locate(8,5) print "hi" And hi would be printed in column 8 line 5. In C++ when I use cout it always prints on the next line, and begins printing in the first column. Is there any way I can do this? C++ itself does not have this feature, it's I/O model is a fairly simple, sequential one. If you want to do fancy cursor positioning, you'll need to output (for example) control characters which your terminal will recognise as special commands (such as ANSI or VT