C++
智渊
这个作者很懒,什么都没留下…
展开
-
ros 旋转矩阵计算欧拉角
void matrix2angle(Eigen::Matrix4f &result_trans, Eigen::Vector3f &result_angle){ double ax, ay, az; if (result_trans(2, 0) == 1 || result_trans(2, 0) == -1) { az = 0; double dlta; dlta = atan2(result_trans(0, 1), result_trans(0, 2)); i.原创 2021-10-30 14:26:12 · 723 阅读 · 0 评论 -
C++ fstream 在文件末尾写入问题
写这篇文章初衷为在使用ofstream时,想在文件末尾追加,但是设置seekp(0,ios::end),每次仍然会覆盖掉之前内容。ofstream流,以ios::app打开(或者“ios::app|ios::out”),如果没有文件,那么生成空文件;如果有文件,那么在文件尾追加。 以ios::app|ios::in打开,不管有没有文件,都是失败。 以ios::ate打开(或者”ios:...转载 2020-04-25 10:38:44 · 9072 阅读 · 0 评论 -
C++ malloc(), memset(),calloc() 区别
本文参考另一篇博客,其链接为:https://blog.csdn.net/ermuzhi/article/details/7833701一、关于C/C++ 几类内存区的说明:栈区(stack):由编译器自动分配与释放,存放函数的参数值,局部变量,临时变量等等;堆区(heap): 一般由程序员分配与释放,基程序员不释放,程序结束时可能由操作系统回收全局区(静态区)(static...转载 2020-02-17 10:59:34 · 465 阅读 · 0 评论 -
VS 2015运行C++程序时控制台输出窗口一闪而过的问题
return 0;之前添加语句system("pasue");不得不说C++字符串必须使用双引号,感觉很死板,但是没有办法啊。原创 2020-02-14 20:02:40 · 666 阅读 · 1 评论 -
PAT A1032 Sharing (25)(25 分)
题目描述:To store English words, one method is to use linked lists and store a word letter by letter. To save some space, we may let the words share the same sublist if they share the same suffix. For e...原创 2018-08-06 16:16:41 · 141 阅读 · 0 评论 -
PAT A1052 Linked List Sorting (25)(25 分)
题目描述:A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Next pointer to the next structure. N...原创 2018-08-07 11:29:32 · 159 阅读 · 0 评论 -
PAT A1020 Tree Traversals (25)(25 分)
题目要求: Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order traversal s...原创 2018-08-14 22:55:06 · 210 阅读 · 0 评论 -
PAT B1013 数素数 (20)(20 分)
题目描述:令P~i~表示第i个素数。现任给两个正整数M <= N <= 10^4^,请输出P~M~到P~N~的所有素数。输入格式:输入在一行中给出M和N,其间以空格分隔。输出格式:输出从P~M~到P~N~的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。输入样例:5 27输出样例:11 13 17 19 23 29 31 3...原创 2018-08-02 22:21:44 · 396 阅读 · 0 评论 -
PAT A1059 Prime Factors (25)(25 分
题目描述:Given any positive integer N, you are supposed to find all of its prime factors, and write them in the format N = p~1~\^k~1~ * p~2~\^k~2~ *…*p~m~\^k~m~.Input Specification:Each input file c...原创 2018-08-03 00:15:11 · 175 阅读 · 0 评论 -
pat A 1053 Path of Equal Weight (30)(30 分)
题目简介:Given a non-empty tree with root R, and with weight W~i~ assigned to each tree node T~i~. The weight of a path from R to L is defined to be the sum of the weights of all the nodes along the pat...原创 2018-08-17 00:57:23 · 458 阅读 · 2 评论 -
PAT A1002 A+B for Polynomials(25 分)
题目要求:This time, you are supposed to find A+B where A and B are two polynomials.Input Specification:Each input file contains one test case. Each case occupies 2 lines, and each line contains the ...原创 2018-09-10 10:34:02 · 265 阅读 · 0 评论 -
PAT A 1060 Are They Equal (25)(25 分)
题目介绍:If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123*10^5^ with simple chopping. Now given the number of ...原创 2018-08-05 23:25:58 · 442 阅读 · 3 评论 -
辗转相除法
求两个数的最大公约数:设两数为a、b(a>b),用gcd(a,b)表示a,b的 最大公约数,r=a (mod b) 为a除以b的余数,k为a除以b的商,即a÷b=k .......r。辗转相除法即是要证明gcd(a,b)=gcd(b,r)。第一步:令c=gcd(a,b),则设a=mc,b=nc第二步:根据前提可知r =a-kb=mc-knc=(m-kn)c第三步:根据第二步结...原创 2018-07-31 21:37:49 · 1339 阅读 · 1 评论 -
PAT A1025【 PAT Ranking】
题目要求:Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the rank...原创 2018-07-23 22:44:28 · 988 阅读 · 0 评论 -
PAT 乙级(B 1020) 月饼
题目要求:(pat B1020)月饼是中国人在中秋佳节时吃的一种传统食品,不同地区有许多不同风味的月饼。现给定所有种类月饼的库存量、总售价、以及市场的最大需求量,请你计算可以获得的最大收益是多少。注意:销售时允许取出一部分库存。样例给出的情形是这样的:假如我们有3种月饼,其库存量分别为18、15、10万吨,总售价分别为75、72、45亿元。如果市场的最大需求量只有20万吨,那么我们最大收益...原创 2018-07-25 12:46:59 · 312 阅读 · 0 评论 -
PAT B 1023 组个最小数
题目描述:给定数字0-9各若干个。你可以以任意顺序排列这些数字,但必须全部使用。目标是使得最后得到的数尽可能小(注意0不能做首位)。例如:给定两个0,两个1,三个5,一个8,我们得到的最小的数就是10015558。现给定数字,请编写程序输出能够组成的最小的数。输入格式:每个输入包含1个测试用例。每个测试用例在一行中给出10个非负整数,顺序表示我们拥有数字0、数字1、……数字9的个数...原创 2018-07-28 22:59:07 · 186 阅读 · 0 评论 -
二分查找法(Binary Search)
在序列按照递增或者递减顺序排列时,我们输入下标left和上标right,每次比较中间值A[mid], ( mid=(left+right)/2),如果A[mid]== x ,return mid;如果A[mid]>x,left=mid+1;如果A[mid]<x,right = mid-1;如果left<right时,返回-1,代表序列中没有该元素。#in...原创 2018-07-28 22:23:05 · 371 阅读 · 0 评论 -
PAT A1001 A+B Format (20)(20 分)
题目要求:Calculate a + b and output the sum in standard format -- that is, the digits must be separated into groups of three by commas (unless there are less than four digits).InputEach input file c...原创 2018-07-29 00:35:19 · 381 阅读 · 0 评论 -
PAT B1009 说反话
009 说反话 (20)(20 分)给定一句英语,要求你编写程序,将句中所有单词的顺序颠倒输出。输入格式:测试输入包含一个测试用例,在一行内给出总长度不超过80的字符串。字符串由若干单词和若干空格组成,其中单词是由英文字母(大小写有区分)组成的字符串,单词之间用1个空格分开,输入保证句子末尾没有多余的空格。输出格式:每个测试用例的输出占一行,输出倒序后的句子。输入样例:Hel...原创 2018-07-23 09:49:49 · 564 阅读 · 0 评论 -
C++ vector的使用
简介:vector可理解为一个可变长度的数组,如果我们无法预先知道需要定义的数组长度时,可以使用vector来进行操作。用法:1.文件包含: 首先在程序开头处加上#include<vector>以包含所需要的类文件vector 需要加上using namespace std;(我们在写算法的过程中需要调用的还有algor...原创 2018-08-04 11:10:39 · 257 阅读 · 0 评论 -
PAT B1040 有几个PAT(25)(25 分)
题目描述: 字符串APPAPT中包含了两个单词“PAT”,其中第一个PAT是第2位(P),第4位(A),第6位(T);第二个PAT是第3位(P),第4位(A),第6位(T)。现给定字符串,问一共可以形成多少个PAT?输入格式:输入只有一行,包含一个字符串,长度不超过10^5^,只包含P、A、T三种字母。输出格式:在一行中输出给定字符串中包含多少个PAT。由于结...原创 2018-07-30 22:56:31 · 274 阅读 · 0 评论 -
set 的用法
简介:set是一个去除掉数组中重复元素并进行排序的集合,学过python的同学应该知道python里面的set类,不一样的地方在于C++类库的set会自动将数组进行排序。如果需要只进行排序当不进行去重,则使用multiset;如果只去重不排序则使用unorder_set;类型名 作用 头文件 set<elemType>name 去重并且排序 ...原创 2018-08-05 10:17:23 · 295 阅读 · 0 评论 -
PAT A1069 The Black Hole of Numbers (20)(20 分)
题目要求:For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained b...原创 2018-07-31 21:09:34 · 212 阅读 · 0 评论 -
PAT B1045 1045 快速排序(25)(25 分)
题目描述: 著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边。 给定划分后的N个互不相同的正整数的排列,请问有多少个元素可能是划分前选取的主元?例如给定N = 5, 排列是1、3、2、4、5。则:1的左边没有元素,右边的元素都比它大,所以它可能是主元;\尽管3的左边元素都比它小,但是...原创 2018-07-31 21:25:31 · 482 阅读 · 0 评论 -
C++ struct的定义
struct的定义格式:struct StructName{ 相关属性;};例如: 我们定义一个student的结构体,其中包含了id,名字,主修专业。struct student{ int id; char name[10]; char major[10];}Alice,stu[1000];注意: 在sruct定义的...原创 2018-07-23 21:24:29 · 7186 阅读 · 0 评论