由买买提看人间百态

topics

全部话题 - 话题: cout
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)
b***i
发帖数: 3043
1
来自主题: Programming版 - ofstream and cout question
I want to use cout or cerr to output something in debug mode, but not
release mode
one way is to
#define myout cout
and use myout always when debug and change the definiton to some null file.
Is there a way to dynamically change the myout if it's declared as
ofstream myout;
such as, myout=cout; (this wouldn't work)
thanks.
g*********s
发帖数: 1782
2
来自主题: Programming版 - RH3/RH4上cout默认格式问题
#include
#include
#include
#include
int main(){
float f = 0.0001;
printf("f = %f\n", f);
printf("f = %g\n", f);
printf("f = %e\n", f);
std::cout <<"f = "< std::cout.setf(std::ios_base::fmtflags(0), std::ios_base::floatfield);
std::cout <<"f = "< }
RH3:
f = 0.000100
f = 1e-04
f = 1.000000e-04
f = 1e-04
f = 1e-04
RH4:
f = 0.000100
f = 0.0001
f = 1.000000e-04
f = 0.0001
f = 0.0001
有啥办法统一格式么?机器是RH3/RH4都有。改程序也
b***i
发帖数: 3043
3
我想把用户输入的所有信息和程序输出的所有信息都输出到一个文件中去,
这样,形成一个log。
有没有简单方法,不用每次用cout<<.......
都再写一个fout<<.....
? 多谢
比如,可不可以fout< 或者,用宏?自定义一个stream?
g*********s
发帖数: 1782
4
来自主题: Programming版 - 很不习惯cin/cout
这个总结挺到位。
不过当年C++大牛们怎么引入cin/cout,又是怎么在程序员里推广的?cin/cout起源也
是别的语言吧?能想出这么别扭的方法,思路独特。

co
g***j
发帖数: 1275
5
【 以下文字转载自 JobHunting 讨论区 】
发信人: gmadj (姑妈爱大舅), 信区: JobHunting
标 题: 问一个reference couting的smart point的问题
发信站: BBS 未名空间站 (Sat Oct 13 19:58:52 2012, 美东)
请问,使用reference couting的smart point的count的值的初始化是在哪儿完成的?
网上很多code,都做到了加1和减1的部分,但是,我按照code打印count的值的时候,
都是random value,但是满足加1和减的关系,因为没有哪个地方初始化这个count的值
。就是第一次使用这个smart point的时候,需要初始化为1吧?
比如这个
http://www.go4expert.com/forums/showthread.php?t=16448
g***j
发帖数: 1275
6
请问,使用reference couting的smart point的count的值的初始化是在哪儿完成的?
网上很多code,都做到了加1和减1的部分,但是,我按照code打印count的值的时候,
都是random value,但是满足加1和减的关系,因为没有哪个地方初始化这个count的值
。就是第一次使用这个smart point的时候,需要初始化为1吧?
比如这个
http://www.go4expert.com/forums/showthread.php?t=16448
l******9
发帖数: 579
7
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: error of couting total line number in txt file on MSDOS
发信站: BBS 未名空间站 (Thu Nov 20 18:34:45 2014, 美东)
I would like to find the total line number of a text file ( > 60 GB) in MS-
DOS.
I used:
findstr /R /N "^" file.txt | find /C ":"
But, the returned result is a negative number.
It is overflow ?
The file have not more than 5 billion lines.
For an integer (4 Bytes), its max range is From −2,147,483,648 to 2,
147,483,64... 阅读全帖
t*****l
发帖数: 121
8
来自主题: Programming版 - cout怎么不换行输出大量字符串?
如果字符串很长的话,cout输出会自动换行。是不是因为stream overflow?
有什么指令可以禁止系统自动换行吗?
t****t
发帖数: 6806
9
来自主题: Programming版 - ofstream and cout question
you can use
ostream& myout=cout;
but you can't change it. if you want to change it, use another scope.
c*****t
发帖数: 1879
10
来自主题: Programming版 - 很不习惯cin/cout
嗯。如果是做 formatted I/O 的话,printf 通过 string template 的办法
(虽然是非常简单的 template)更好用一些。scanf 自带一定程度的 regex 。
用好了可以出来大部分相对复杂的 input 。
cin/cout 的 << >> 只是给简单的 I/O 使用。
n******n
发帖数: 12088
11
来自主题: Programming版 - 很不习惯cin/cout
1. 如果有些需要模板,有些不需要呢?比如50%对50%,混着用?
2. cin/cout为什么不能设计的更好用?当年这个设计是怎么来的?
a***y
发帖数: 2803
12
来自主题: Programming版 - cout << ("hi" + "hi")
cout <<"hi" <<"hi";
p***o
发帖数: 1252
13
来自主题: Programming版 - cout << ("hi" + "hi")
Why bother? Just use cout << "hi" "hi";
a***y
发帖数: 2803
14
来自主题: Programming版 - cout << ("hi" + "hi")
why bother? just use cout<<"hihi";
t*****n
发帖数: 225
15
来自主题: Programming版 - cout << ("hi" + "hi")
do you mean this?
//
cout<<(string("hi")+=string("hi")).c_str();
//
l******9
发帖数: 579
16
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: error of couting total line number in txt file on MSDOS
发信站: BBS 未名空间站 (Thu Nov 20 18:34:45 2014, 美东)
I would like to find the total line number of a text file ( > 60 GB) in MS-
DOS.
I used:
findstr /R /N "^" file.txt | find /C ":"
But, the returned result is a negative number.
It is overflow ?
The file have not more than 5 billion lines.
For an integer (4 Bytes), its max range is From −2,147,483,648 to 2,
147,483,64... 阅读全帖
l******9
发帖数: 579
17
【 以下文字转载自 JobHunting 讨论区 】
发信人: light009 (light009), 信区: JobHunting
标 题: error of couting total line number in txt file on MSDOS
发信站: BBS 未名空间站 (Thu Nov 20 18:34:45 2014, 美东)
I would like to find the total line number of a text file ( > 60 GB) in MS-
DOS.
I used:
findstr /R /N "^" file.txt | find /C ":"
But, the returned result is a negative number.
It is overflow ?
The file have not more than 5 billion lines.
For an integer (4 Bytes), its max range is From −2,147,483,648 to 2,
147,483,64... 阅读全帖
s******t
发帖数: 150
18
来自主题: Computation版 - c++,如何用cout 输出double 变量
使用dev c++,
代码如下:
#include
#include
#include
using namespace std;
//------------------------------------
//-------- main()---------------------
//====================================
int main(int argc, char *argv[])
{
double a = 5.0;
cout << a <<endl;//
system("PAUSE");
return EXIT_SUCCESS;
}
//---------------------------------
Compiler: Default compiler
Building Makefile: "C:\Users\Documents\c++\learnCplus_OOP1\Makefile.win"
Executing make...
make.exe -f "C:... 阅读全帖
f****4
发帖数: 1359
19
来自主题: JobHunting版 - 问个面试题
void printspiral(char *a, int colsize, int m, int n, int x0, int y0)
{
// a is the matrix, colsize is its original column size
// m is #rows, n is #cols in the submatrix
// x0 and y0 are the offsets of the first element of the submatrix
// check if m and n are positive
if (m<=0 || n<=0) {
cout << "zero or negative dimensions" << endl;
return;
}
int i;
if(m>=2&&n>=2) {
// print the outer circle
for(i=0; i<=n-2; i++)
cout << a[x0*c... 阅读全帖
S**I
发帖数: 15689
20
☆─────────────────────────────────────☆
careerchange (Stupid) 于 (Sat Jun 4 20:25:58 2011, 美东) 提到:
void reversePrint(Node* head) {
if(head=NULL) {
cout << "Empty List. No node to print." << endl;
return;
}
if(head->next=NULL) {
cout << head->data << endl;
return;
} else {
Node* temp=head;
head=temp->next;
reversePrint(head);
cout << temp->data << endl;
return;
}
}
☆─────────────────────────────────────☆
speeddy (Wade) 于 (Sat Jun 4 20:30:33 ... 阅读全帖
g*********s
发帖数: 1782
21
来自主题: Programming版 - protected/private inheritance
Just did a quick test. So what's the diff b/w private inheritance and
protected inheritance here?
#include
using namespace std;
class B {
public:
void f() { cout << "B::f()\n"; }
virtual void g() { cout << "B::g()\n"; }
int B_public;
protected:
int B_protected;
private:
int B_private;
};
class D_pub: public B {
public:
void f() { cout << "D_pub::f()\n"; }
virtual void g() { cout << "D_pub::g()\n"; }
void h() { cout << B_protected << endl; }
//void j... 阅读全帖
d****o
发帖数: 2
22
来自主题: JobHunting版 - 面试F家让先做programming puzzle
抛砖引玉
#include
#include
#include
const int kMaxK = 5;
const int kMaxN = 8;
const int kMaxS = 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5;
#define DEBUG(v) std::cerr << #v << " = " << (v) << "\n"
int N, K, max_state;
short top[kMaxS][kMaxK];
int G[kMaxS][kMaxK * (kMaxK - 1) + 1];
int src = 0, dst = 0;
int f[kMaxS];
int pow(int base, int power) {
int r = 1;
for (int i = 0; i < power; r *= base, ++i);
return r;
}
int get(int num, int d) {
for (int i = 0; i < d; num /= K, ++i)... 阅读全帖
d****o
发帖数: 2
23
来自主题: JobHunting版 - 面试F家让先做programming puzzle
抛砖引玉
#include
#include
#include
const int kMaxK = 5;
const int kMaxN = 8;
const int kMaxS = 5 * 5 * 5 * 5 * 5 * 5 * 5 * 5;
#define DEBUG(v) std::cerr << #v << " = " << (v) << "\n"
int N, K, max_state;
short top[kMaxS][kMaxK];
int G[kMaxS][kMaxK * (kMaxK - 1) + 1];
int src = 0, dst = 0;
int f[kMaxS];
int pow(int base, int power) {
int r = 1;
for (int i = 0; i < power; r *= base, ++i);
return r;
}
int get(int num, int d) {
for (int i = 0; i < d; num /= K, ++i)... 阅读全帖
v******y
发帖数: 84
24
来自主题: Programming版 - 前几天有人问rvalue reference的
这是我的理解,不对的请指出,谢谢
The usage of rvalue reference &&
Define a class
class MyClass{
public:
MyClass(){/*require for const MyClass cMyClass init. Without this default
constructor, const MyClass will have to be declared and defined as such:
const MyClass cMyClass=MyClass(). MyClass() here will call synthesized
constructor automatically generated by compiler. This synthesized
constructor can not directly initiate const. So following is illegal without
default constructor: const MyClass cMyClass;*/}
};... 阅读全帖
s*w
发帖数: 729
25
just practicing c++11 multi-threading and got the following code to try out
your example
problem with my code now:
1. it does not deal with last line of input file
2. it has deadlock for certain test file
Anyone familiar with c++11 multi-threading?
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
const int MAXCAPACITY = 3;
mutex mx;
deque data;
map阅读全帖
s*w
发帖数: 729
26
发信人: yangguo1220 (yangguo), 信区: JobHunting
标 题: 一道count frequency of all words的面试题
发信站: BBS 未名空间站 (Wed Sep 18 20:44:44 2013, 美东)
100G的文本文件,4G内存,4个CPU。写一个程序:列出所有文本文件中的word
frequency,并output到一个最终文件中, 格式为 . 这个最终文件
的size也可能比内存小.
大家有啥建议?
【 以下文字转载自 JobHunting 讨论区 】
发信人: saw (句子熊), 信区: JobHunting
标 题: Re: 一道count frequency of all words的面试题
发信站: BBS 未名空间站 (Thu Sep 19 02:18:15 2013, 美东)
just practicing c++11 multi-threading and got the following code to try out
your example
problem wi... 阅读全帖
p****e
发帖数: 37
27
来自主题: JobHunting版 - 两道F电面题
贴个楼主事后写的:
bool _re_match(const char *str, const char *pattern, char prev_char) {
// 如果str匹配完,检查pattern是否匹配完,或者还剩一个"*"
if (*str == NULL)
return (*pattern == NULL || (*pattern == '*' && *(pattern+1) == NULL
)) ? true : false;
if (*pattern != '*')
{
// 如果当前pattern char不是'*', 试图匹配当前的str char, 然后
继续。
if (*pattern == '.' || *pattern == *str)
{
if (_re_match(str+1, pattern+1, *pattern))
return true;
... 阅读全帖
p****e
发帖数: 37
28
来自主题: JobHunting版 - 两道F电面题
贴个楼主事后写的:
bool _re_match(const char *str, const char *pattern, char prev_char) {
// 如果str匹配完,检查pattern是否匹配完,或者还剩一个"*"
if (*str == NULL)
return (*pattern == NULL || (*pattern == '*' && *(pattern+1) == NULL
)) ? true : false;
if (*pattern != '*')
{
// 如果当前pattern char不是'*', 试图匹配当前的str char, 然后
继续。
if (*pattern == '.' || *pattern == *str)
{
if (_re_match(str+1, pattern+1, *pattern))
return true;
... 阅读全帖
a******e
发帖数: 124
29
来自主题: JobHunting版 - 请教一下怎么写unit test
以前写程序test时候只是在main函数里简单输出一下看看对不对,最近想学一下unit
test,这个有什么格式要求吗(我看有些人用assert())?比如用c++语言想写一个
binary search的unit test该如何写,谢谢!
试着写了一个,不知道这样算不算unit test
#include
using namespace std;
int BinarySearch(int arr[], int size, int target){
int high=size-1;
int low=0;
int mid;
while(low<=high){
mid=low+(high-low)/2;
if(arr[mid]==target){
return mid;
}
else if(arr[mid]>target){
high=mid-1;
}
else{
low... 阅读全帖
h********1
发帖数: 344
30
下边的这个CS的图标有没有更好的CODING 方法,或者更FANCY的方法。
#include
using namespace std;
int main()
{
cout<<"********************************************
\n";

cout<<" C C C S S S S !!\n";
cout<<" C C S S !!\n";
cout<<" C S !!\n";
cout<<" C S !!\n";
cout<<" C S S S S !!\n";
... 阅读全帖
s****n
发帖数: 700
31
来自主题: Programming版 - a question about bitwise operation
那看看这个code
#include
using namespace std;
int main() {
int i;
unsigned int ui;
long l;
unsigned long ul;
long long ll;
unsigned long long ull;
i = 1 << (sizeof(i) * 8 - 1);
cout << "sizeof(i) is " << sizeof(i) << endl;
cout << "i is " << i < ui = 1 << (sizeof(ui) * 8 - 1);
cout << "sizeof(ui) is " << sizeof(ui) << endl;
cout << "ui is " << ui < l = 1 << (sizeof(l) * 8 - 1);
cout << "sizeof(l) is " << sizeof(l) << endl;
cout << "l is " << l < ul = 1 << (sizeof(ul) * 8 -... 阅读全帖
J**********y
发帖数: 1891
32
#include "stdafx.h"
#include
#include
using namespace std;
class Base
{
public:
Base(){ cout << "Base-ctor"< ~Base(){cout << "Base-dtor"< virtual void f(int) {cout << "Base::f(int)"< virtual void f(double) {cout << "Base::f(double)"< virtual void g(int i=10) {cout << "Base::g()"< void g2(int i=10) {cout << "Base::g2()" << i< };
class Derived : public Base
{
public:
Derived() {cout << "Derived-ctor... 阅读全帖
e********r
发帖数: 2352
33
来自主题: JobHunting版 - Epic Written Interview
在本地的考试中心预约的上机考试。考试有三个部分,1.数学题,2.给出一种新的编程
语言的语法,回答相应问题,3. Programming Test 要求速度和准确性both important
Programming test 答得不好,肯定不行了,把面试题发上来让大家做做。做了3个半小
时,快累死了。
数学题基本上就是脑筋急转弯,举几个例子
1. You have three kinds of magazines, all but two are Times, all but two are
Science, all but two are Nature. How many magazines in total do you have?
3 books
2. Only one of the answers is true
A. All of the below are true
B. All answers are true
C. One of the above is true
D. All of the above are true
E. None of the above ar... 阅读全帖
S**I
发帖数: 15689
34
来自主题: JobHunting版 - C++ Q83: 这个const_cast什么意思?
I bet if you run a debugger for this example, you will see that both a and *
b have value 3 after "*b = 3", but the output of "std::cout << a" is still 2.
The reason is when compiler sees "std::cout << a", since a is declared as
const and initialized to 2, it may replace this statement with "std::cout <<
2". The compiler never bothers to check whether the value of a has been
modified before "std::cout << a". This is a valid optimization and many
compilers do it.
Change you code to the following ... 阅读全帖
L**********u
发帖数: 194
35
来自主题: JobHunting版 - Exposed上一道string permutation的题
This problem can be solved by binary representation of an integer.
I am a rookie of C++. thanks for comments
my codes
#include
#include
#include
using namespace std;
const int N=5;
void subset(int arr[], int n)
{
bitset n_bit(n);
cout<<"{";
for(int i=0;i if(n_bit[i]==1)
cout< cout<<"};";
cout< }
//main function
int main()
{
cout<<"The set has "< int arr[N];
for(int i=0;i arr[i]=... 阅读全帖
w*******r
发帖数: 2953
36
来自主题: JobHunting版 - 一道OO设计题
改完的程序在下面,这下疾病可以随便定义了,也可以治病了。
想给给个病安个计数器,记得好像有个什么关健词可以让所有的object改动的都是
同一个变量而不是各自的变量(counter),记不起来了,所以这个counter打印得
不对,有知道的告诉我一声。
#include
#include
#include
using namespace std;
class Disability
{
public:
Disability(){counter = 0; };
Disability(string, string);
~Disability(){};
string get_disease_name() const { return name; };
string get_disease_desc() const { return desc; };
void incr_sick_human_counter() {counter++; };
unsigned long get_hum... 阅读全帖
f*******t
发帖数: 7549
37
来自主题: JobHunting版 - 2道算法题。 求教大家!
找出了一年多前写的逆波兰处理算数表达式的代码,强烈建议有兴趣的自己实现一下:
#include
#include
#include
#include
#define BUFFSIZE 1024
using namespace std;
struct Token {
bool isNum;
int num;
char op;
Token();
Token(const Token& t);
};
Token::Token()
{
isNum = false;
num = 0;
op = 0;
}
Token::Token(const Token& t)
{
isNum = t.isNum;
num = t.num;
op = t.op;
}
Token *getToken(const char expr[], int& idx)
{
Token *res = NULL;
while(expr[idx] == ' ')
... 阅读全帖
c*******a
发帖数: 1879
38
这种弱智儿童也能够进谷歌
看来谷歌是世风日下 将是i现在的IBM和诺基亚的后果
【 以下文字转载自 JobHunting 讨论区 】
发信人: zengqinghan (Zzz), 信区: JobHunting
标 题: Re: 面试结束,晒3个 Java面试题,请大家讨论。
发信站: BBS 未名空间站 (Sat Nov 18 15:24:05 2017, 美东)
第三提我也见到过,不过是C++的,其实很简单,就是a执行完解锁b,b执行完解锁c...
开始就a解锁就行了。Java的不懂。
参考代码:
#include
#include
#include
using namespace std;
class Solution
{
mutex mutexa, mutexb, mutexc;
int N = 0;
void threada()
{
for (int i = 0; i < N; ++i)
{
mutexa.lock();
... 阅读全帖
c*******a
发帖数: 1879
39
【 以下文字转载自 JobHunting 讨论区 】
发信人: justicezyx (just), 信区: JobHunting
标 题: Re: 大家看看一个自称狗家码农写的代码 (转载)
发信站: BBS 未名空间站 (Sun Nov 19 17:50:19 2017, 美东)
几个细节,跟google c++代码要求差别比较大。
这个代码我是看不懂在做什么。
#include
#include
#include
using namespace std;
// using declarations on namespace is banned in google c++ code
class Solution
{ // this is not the style used in google, if you write c++ in google, I
feel very difficult to believe that you can resist the muscle memory and
uses a differ... 阅读全帖
m******e
发帖数: 353
40
来自主题: JobHunting版 - one amazon interview problem
#include
#include
void countOnesAndZeros(int &numZeros, int &numOnes, const std::vector &
sequence) {
numOnes = 0;
numZeros = 0;
for(size_t i = 0; i sequence[i] == 1 ? ++ numOnes : ++ numZeros;
}
}
int trimLeft(const std::vector &sequence, int start, int numToTrim, int
untilSeenSymbol) {
int trimCnt = 0;
while(start + trimCnt >= 0 && start + trimCnt < (int) sequence.size() &&
numToTrim > 0) {
if(sequenc... 阅读全帖
s******c
发帖数: 1920
41
来自主题: JobHunting版 - CS interview question
任意取两点,计算斜率和截距,能得到一条直线,然后把其他落在这条直线上的点也打
印出来。用一个set保存unique的(斜率,截距),这样不会重复选取。特殊情况是斜
率为无穷大,没有截距。
=============================================
#include
#include
using namespace std;
#define N 5
class Line{ //y=a*x+b
public:
float a,b;
Line ():a(0),b(0){}
Line (int n1,int n2):a(n1),b(n2){}
bool operator<(const Line &right)const{
if (a==right.a)
return b else return a }
bool operator==(const Line &right)const{
... 阅读全帖
c********2
发帖数: 56
42
来自主题: JobHunting版 - 贴个FLEXTRADE的在线C++测试的题
面的是Associate C++ Developer,下面是面试题,光顾着记题了,最后只有56%的通过
率,要到
80%才能ONSITE,算是帮大家做点贡献吧,他家在招人,赶快去投简历
1) #include
using namespace std;
struct A{
A(int value) : m_value(value){}
int m_value;
};
struct B:A {
B(int value):A(value){}
};
int main(){
try {
try{
throw B(5);
}
catch(A a){
a.m_value *=2;
throw;
}
catch(B b){
b.m_value -=2;
throw b;
}
}
catch(A a){
... 阅读全帖
e*****w
发帖数: 144
43
加减乘,没用+-*/号。
#include
using namespace std;
int Add(int a, int b) {
return (b ? Add(a ^ b, (a & b) << 1) : a);
}
int Sub(int a, int b) {
return Add(a, Add(~b, 1));
}
int Mul(int a, int b) {
if (b == 0) return 0;
if (b < 0) return Mul(Sub(0, a), Sub(0, b));
return Add(a, Mul(a, Sub(b, 1)));
}
int main() {
cout << "Add(3, 4) = " << Add(3, 4) << endl;
cout << "Add(3, -8) = " << Add(3, -8) << endl;
cout << "Add(-8, 40) = " << Add(-8, 40) << endl;
cout << "Sub(3, 4) = " <<... 阅读全帖
e*****w
发帖数: 144
44
加减乘,没用+-*/号。
#include
using namespace std;
int Add(int a, int b) {
return (b ? Add(a ^ b, (a & b) << 1) : a);
}
int Sub(int a, int b) {
return Add(a, Add(~b, 1));
}
int Mul(int a, int b) {
if (b == 0) return 0;
if (b < 0) return Mul(Sub(0, a), Sub(0, b));
return Add(a, Mul(a, Sub(b, 1)));
}
int main() {
cout << "Add(3, 4) = " << Add(3, 4) << endl;
cout << "Add(3, -8) = " << Add(3, -8) << endl;
cout << "Add(-8, 40) = " << Add(-8, 40) << endl;
cout << "Sub(3, 4) = " <<... 阅读全帖
w*******s
发帖数: 96
45
再来一个拍拍:
////////////////////////////////////////////////////////////////////////////
////////
// Problem 1.1:
// Analysis and points:
// 1. strig operation(scan)
// 2. How to determine whether it's duplicate string?
// Method 1: using one hashtable, if it's already in
hashtable,
// it's duplicate, otherwise add into hashtable.
Complexity O(n)
// Method 2: for each characer, check whether it's duplicated
// ... 阅读全帖
v******9
发帖数: 1
46
来自主题: JobHunting版 - 请教一个OOP的C++问题
可以不需要typeid,不过就比较奇怪一点。
tester.h
================
class A{
public:
virtual void invoke();
};
class B:public A{
public:
void virtual invoke();
};
class C:public A{
public:
void invoke();
};
class D:public A{
public:
void invoke();
};
=====================
main.cpp
=====================
#include
#include
#include "tester.h"
using namespace std;
void test(A* a){
cout<<"test: A "< };
void test(B* a){
cout<<"test: B "< };
void test(C* a){
co... 阅读全帖
s*w
发帖数: 729
47
来自主题: JobHunting版 - [leetcode] merge k lists 求助
不知道为啥,我的 heap 时灵时不灵的?请看下面的 code 和输出显示
#include
#include
#include
using namespace std;
struct ListNode {
int val;
ListNode *next;
ListNode(int v):val(v),next(NULL) {}
};
bool minHeapPredicate(ListNode* lhs,ListNode* rhs) {
return lhs->val > rhs->val;
}
class Solution {
public:
ListNode *mergeKLists(vector lists) {
ListNode *retHead = NULL, *retTail = NULL;
// store values and nodes into heap
vector ... 阅读全帖
z*********n
发帖数: 1451
48
第三提我也见到过,不过是C++的,其实很简单,就是a执行完解锁b,b执行完解锁c...
开始就a解锁就行了。Java的不懂。
参考代码:
#include
#include
#include
using namespace std;
class Solution
{
mutex mutexa, mutexb, mutexc;
int N = 0;
void threada()
{
for (int i = 0; i < N; ++i)
{
mutexa.lock();
cout<<"A ";
cout< mutexb.unlock();
}
}
void threadb()
{
for (int i = 0; i < N; ++i)
{
... 阅读全帖
z****e
发帖数: 2024
49
来自主题: Programming版 - 大家来做题C++。
#include
using namespace std;
class blah{
public:
blah(int i):_i(i){
cout<<"blah()"< }
~blah(){
cout<<"~blah("<<_i<<")"< }
int get(){
cout<<_i< }
private:
int _i;
};
class base{
public:
base():ob(3){
i=0;
cout<<"base()"< }
void out(){
cout<<"base.out()"< }
void f(){
cout<<"base.f()"< cout<<"i= "< cout<<"ob.get()= "< }
~base(){
cout<<"~base()"< }
vo
1 2 3 4 5 6 7 8 9 10 下页 末页 (共10页)