cout

数据结构-单链表-类定义2-C++

情到浓时终转凉″ 提交于 2019-12-03 06:38:09
上一次 的C++链表实现两个单链表的连接不太理想,此次听了一些视频课,自己补了个尾插法,很好的实现了两个链表的连接,当然了,我也是刚接触,可能是C++的一些语法还不太清楚,不过硬是花了一些时间尽量在数据结构中将c++的语言特点表现出来。一开始也是不愿意读c++的数据结构,只是一种挑战心里,不想读着读着感觉自己太low了,c++的内容更加丰富,所以还得多多练习...... 头文件 1 #ifndef LIST_H 2 #define LIST_H 3 #include <iostream> 4 5 template <class Type> class List; //前置声明 6 template <class Type> class ListIterator; //前置声明 7 8 //创建结点类 9 template <class Type> //类模板 10 class ListNode 11 { 12 friend class List<Type>; //友元函数--29行 13 friend class ListIterator<Type>; //友元函数--46行 14 private: 15 Type data; 16 ListNode *link; 17 ListNode(Type); 18 }; 19 20 template <class Type> 21

CF1137D题解

吃可爱长大的小学妹 提交于 2019-12-03 05:10:02
神仙交互题 记得以前听lch神仙讲过,不过当时还没做过这道题 题意(来自yyb神仙的翻译): 有一张图是由一个长度为t的链和一个大小为c的环中间连上一条边组成的。 假如这条边连接的是链的右端点,和环上的T点。 令链的左端点是S。 现在在S处有10个棋子,编号0−9,每次你可以让任意数量的棋子向出边方向走一步,交互库会返回若干个集合,每一个集合内的棋子都在同一个位置上,并且这个位置上的所有棋子都在这个集合中。 现在你既不知道t也不知道c。你需要使用不超过3(t+c)次操作使得所有棋子都移动到T位置上并且返回交互库 官方题解翻译......(手动翻译,不是机翻) 棋子的数量在这里是迷惑你的,其实只需要三个棋子就可以解决问题 我们把移动速度快的棋子叫做fast,慢的叫slow,slow每走一步,fast走两步,当他们相遇时停止 显然,slow无法在环上走完完整的一圈,因为slow每走1圈,fast走两圈,一定会被fast追上 故他们相遇时行走的距离 \(slow=t+x\) , \(fast=t+x+k*c\) ,且 \(fast=2*slow\) 解得 \(x≡-t(mod c)\) 所以再走t步就能到达终点了,但我们不知道t是多少,注意到留在原点的棋子离终点距离刚好为t,故让所有棋子同时走,相遇时就都到达了终点 询问次数q=2 t+2 x+t=2 x+3 t<3*(x+t)

getting cout output to a std::string

别等时光非礼了梦想. 提交于 2019-12-03 04:17:22
I have the following cout statement. I use char arrays because I have to pass to vsnprintf to convert variable argument list and store in Msg . Is there any way we can get cout output to C++ std::string ? char Msg[100]; char appname1[100]; char appname2[100]; char appname3[100]; // I have some logic in function which some string is assigned to Msg. std::cout << Msg << " "<< appname1 <<":"<< appname2 << ":" << appname3 << " " << "!" << getpid() <<" " << "~" << pthread_self() << endl; Björn Pollex You can replace cout by a stringstream . std::stringstream buffer; buffer << "Text" << std::endl;

isdigit() c++, probably simple question, but stuck

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm having trouble with isdigit. I read the documentation, but when I cout << isdigit(9), I get a 0. Shouldn't I get a 1? #include <iostream> #include <cctype> #include "Point.h" int main() { std::cout << isdigit(9) << isdigit(1.2) << isdigit('c'); // create <int>i and <double>j Points Point<int> i(5, 4); Point<double> *j = new Point<double> (5.2, 3.3); // display i and j std::cout << "Point i (5, 4): " << i << '\n'; std::cout << "Point j (5.2, 3.3): " << *j << '\n'; // Note: need to use explicit declaration for classes Point<int> k; std:

How to print RSA* as string in C++?

匿名 (未验证) 提交于 2019-12-03 02:27:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: How to properly print RSA* as string in C++? I am using OpenSSL . It doesn't seem to have a .c_str() method, right? 回答1: RSA_print_fp(stdout, x, 0); http://linux.die.net/man/3/rsa_print_fp 回答2: #include <iostream> using std::cout; using std::endl; #include <string> using std::string; #include <memory> using std::unique_ptr; #include <openssl/bn.h> #include <openssl/rsa.h> #include <openssl/bio.h> #include <openssl/buffer.h> #include <cassert> #define ASSERT assert using BN_ptr = std::unique_ptr<BIGNUM, decltype(&::BN_free)>; using RSA_ptr =

mysql自增id列

余生颓废 提交于 2019-12-03 02:18:06
如果希望在每次插入新记录时,自动地创建主键字段的值。可以在表中创建一个 auto-increment 字段。MySQL 使用 AUTO_INCREMENT 关键字来执行 auto-increment 任务。默认地AUTO_INCREMENT 的开始值是 1,每条新记录递增 1。 主键又称主关键字,主关键字(primary key)是表中的一个或多个字段,它的值用于唯一地标识表中的某一条记录。 测试创建一个test表: mysql> create table test ( aid int not null auto_increment, site_id int, cout int, date date, primary key (aid) ); Query OK, 0 rows affected (0.01 sec) mysql> desc test; +---------+---------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+---------+------+-----+---------+----------------+ | aid | int(11) | NO | PRI | NULL | auto

What are the signs of crosses initialization?

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Consider following code: #include <iostream> using namespace std; int main() { int x, y, i; cin >> x >> y >> i; switch(i) { case 1: // int r = x + y; -- OK int r = 1; // Failed to Compile cout << r; break; case 2: r = x - y; cout << r; break; }; } G++ complains crosses initialization of 'int r' .My questions are: What is crosses initialization ? Why do the first initializer x + y pass the compilation,but the later failed? What are the problems of so-called crosses initialization ? EDIT : I know I should use brackets to specify the scope of r

What&#039;s the difference between cout&lt;&lt;cout and cout&lt;&lt;&amp;cout in c++?

匿名 (未验证) 提交于 2019-12-03 01:34:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: This might be a beginner question and understanding how cout works is probably key here. If somebody could link to a good explanation, it would be great. cout and cout print hex values separated by 4 on a linux x86 machine. 回答1: cout is equivalent to cout . This is the idiom used before C++11 to determine if an iostream is in a failure state, and is implemented in std::ios_base ; it usually returns the address of static_cast (&cout) . cout prints out the address of cout . Since std::ios_base is a virtual base class of cout , it may not

How to make C++ cout not use scientific notation

匿名 (未验证) 提交于 2019-12-03 01:29:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: double x = 1500; for(int k =0; k this the output Bas ana: 3284.78 Son faiz: 1784.78 Son ana: 5069.55 Bas ana: 7193.17 Son faiz: 3908.4 Son ana: 11101.6 Bas ana: 15752 Son faiz: 8558.8 Son ana: 24310.8 Bas ana: 34494.5 Son faiz: 18742.5 Son ana: 53237 Bas ana: 75537.8 Son faiz: 41043.3 Son ana: 116581 Bas ana: 165417 Son faiz: 89878.7 Son ana: 255295 Bas ana: 362238 Son faiz: 196821 Son ana: 559059 Bas ana: 793246 Son faiz: 431009 Son ana: 1.22426e+006 Bas ana: 1.73709e+006 Son faiz: 943845 Son ana: 2.68094e+006 Bas ana: 3.80397e+006 Son faiz

Google::protobuf + boost::asio failure

匿名 (未验证) 提交于 2019-12-03 01:18:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I have studied the existing examples: Sending Protobuf Messages with boost::asio Reading Protobuf objects using boost::asio::read_async Google Protocol Buffers: parseDelimitedFrom and writeDelimitedTo for C++ Are there C++ equivalents for the Protocol Buffers delimited I/O functions in Java? Sending Protobuf Messages with boost::asio but I still can not figure out how to pass Google Protobuf messages using the Boost::asio API. In particular I have no clear understanding of the following problems: Interaction between boost::asio: