boost不是標(biāo)準(zhǔn)庫(kù),但它仍然是庫(kù)。<>
就是優(yōu)先搜庫(kù),沒(méi)毛病。
你要是用其他的庫(kù),也得用<>
。
首先,n<2 類(lèi)似于初始化,F(xiàn)ib(0) = 0, Fib(1) = 1;第一個(gè)return就返回了,不會(huì)執(zhí)行下面的打印。
然后,n>2時(shí),F(xiàn)ib(2) = Fib(1) + Fib(0),會(huì)打印Fib(1)和Fib(0)。
這個(gè)就是斐波那契數(shù)列的一邊表達(dá)式:f(n) = f(n-1) + f(n-2)。
"010203".match(/\d{2}/g);
或者
"010203".split(/\B(?=(?:\d{2})+\b)/);
或者
"010203".split(/\B(?=0)/);
c++ primer???
看少俠這代碼,RoomBusiness這個(gè)類(lèi)應(yīng)該是以單例模式寫(xiě)的吧,所以?xún)煞N方法沒(méi)區(qū)別
vector<int>
無(wú)需釋放內(nèi)存,但是vector<string>
需要swap釋放
當(dāng)然你會(huì)疑惑 int無(wú)需釋放內(nèi)存,string 也無(wú)需釋放內(nèi)存(會(huì)自動(dòng)析構(gòu)釋放),但是為什么在vector中不一樣?vector<int>
等內(nèi)置類(lèi)型無(wú)需釋放內(nèi)存,自動(dòng)釋放。string類(lèi)型的本質(zhì)是指針,vector<string>
,vector<int*>
等指針類(lèi)型需要手動(dòng)swap釋放。
我認(rèn)為使用define的最大價(jià)值在于是否可以將大段的重復(fù)性代碼濃縮為define,后續(xù)使用可能用一個(gè)宏就解決大段的重復(fù)性代碼。比如mfc中的消息映射,成功的將很多重復(fù)性的代碼濃縮為一兩個(gè)宏,雖然mfc本身很復(fù)雜,但是它的宏定義的使用堪稱(chēng)教科書(shū)。其他常用的使用場(chǎng)景比如定義不定長(zhǎng)的函數(shù),你給出的這個(gè)例子就是。比如與操作系統(tǒng)和編譯環(huán)境有關(guān)的,比如__FILE__,__LINE__,DEBUG等。至于你講的可能的代替,我認(rèn)為是定義常量、定義簡(jiǎn)單的函數(shù)等。
behavior
屬性只有IE兼容吧? 應(yīng)該要盡量避免使用
@course.comments.sum{ |cc| cc.comment.length }
&的用意我只知道除了是引用和位址之外,它還有一個(gè)功能就是防止拷貝(比較有效率)。
void swap(int &a, int &b)
和
void swap(int a, int b)
的差別是一個(gè)是整數(shù)a b的本身,另一個(gè)是整數(shù)a b的副本。如果你使用第二個(gè)swap函數(shù)來(lái)進(jìn)行交換整數(shù)的話,你會(huì)發(fā)現(xiàn)沒(méi)有換到。因?yàn)槟闼幚淼闹皇窃诟北旧线M(jìn)行交換整數(shù)而已,它本身的自己卻沒(méi)有更動(dòng)到。
Box operator+(const Box& b)
{
Box box;
box.length = this->length + b.length;
box.breadth = this->breadth + b.breadth;
box.height = this->height + b.height;
return box;
}
知道了&的一些概念后,你可能會(huì)問(wèn)為什么 Box& b前面要放 const!
因?yàn)槟阒?&會(huì)改變對(duì)象本身,然后我們只是想用b里面的變數(shù)且不想更動(dòng)到它們,所以前面加const的用意是防止改變對(duì)象!
總結(jié)來(lái)說(shuō),const B &b 達(dá)到了無(wú)副本 + 無(wú)法修改的目的。
如 sserver 日志所示
15 E0403 17:24:39.589262 4886 Utils.cc:221] unable to request data from: https://127.0.0.1/get_user_id_list?last_id=0, error: Couldn't connect to server
16 E0403 17:24:39.589727 4886 StratumServer.cc:480] http get request user list fail, url: https://127.0.0.1/get_user_id_list?last_id=0
17 E0403 17:24:39.589777 4886 StratumServer.cc:547] update user list failure
18 E0403 17:24:39.589867 4886 StratumServer.cc:776] fail to setup server
19 F0403 17:24:39.589912 4886 StratumServerMain.cc:171] init failure
參考 sserver.cfg 的注釋?zhuān)阈枰约捍罱ㄒ粋€(gè)網(wǎng)站服務(wù)器(xx.yy),并提供一個(gè)網(wǎng)站接口(/get_user_id_list),然后把網(wǎng)址寫(xiě)入 sserver.cfg 文件的 list_id_api_url 項(xiàng),如下
users = {
list_id_api_url = "http://xx.yy/get_user_id_list";
};
你可以在本機(jī)搭建一個(gè) apache 或者 nginx 服務(wù)器,然后按照
https://github.com/btccom/btc...
上的說(shuō)明操作便可。
select操作不會(huì)造成死鎖。我猜測(cè):update語(yǔ)句有大字段更新,導(dǎo)致事務(wù)時(shí)間較長(zhǎng)(即長(zhǎng)事務(wù)),同時(shí),其他select語(yǔ)句引起update操作,當(dāng)update同一條記錄時(shí),就會(huì)導(dǎo)致死鎖(等待長(zhǎng)事務(wù)的完成)。
可重入鎖不是這么用的,一般是在面向?qū)ο笾惺褂?,比?/p>
class A:
def f1(self):
mutex.acquire()
try:
#do something
finally:
mutex.release()
def f2(self):
mutex.acquire()
try:
#do something
finally:
mutex.release()
def run1(obj):
obj.f1()
obj.f2()
def run2(obj):
obj.f2()
obj.f1()
obj1 = A()
t1 = threading.Thread(target=run1, args=(obj1, ))
t2 = threading.Thread(target=run2, args=(obj1, ))
t1.start()
t2.start()
調(diào)用順序不同,而且都需要同步的時(shí)候,如果不用遞歸鎖,會(huì)死鎖。如果f1或f2不加鎖,數(shù)據(jù)不同步,報(bào)錯(cuò)
sem_init函數(shù)入?yún)⑿枰獋魅虢Y(jié)構(gòu)體地址,即sem_t mutex;
sem_init(&mutex);
還有看到你buffer定義是數(shù)組指針,但感覺(jué)初始化是按照字符數(shù)組初始化的。
不用 inplace (直接分成兩個(gè)數(shù)組排序,再合并) 的話就太簡(jiǎn)單了,要 inplace 的話其實(shí)也可以不用手寫(xiě) iterator,手寫(xiě)一個(gè) reference 的 wrapper 就行了(然后直接調(diào)用任意 常規(guī) inplace 排序算法即可):
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;
template <typename T>
class Ref {
T & t;
public:
Ref(T & t) : t(t) {
}
Ref(Ref & o) : t(o.t) {
}
Ref(Ref && o) : t(o.t) {
}
Ref & operator = (Ref & o) {
t = o.t;
return *this;
}
Ref & operator = (Ref && o) {
t = move(o.t);
return *this;
}
bool operator < (Ref const & o) const {
return t < o.t;
}
friend void swap(Ref & a, Ref & b) {
using std::swap;
swap(a.t, b.t);
}
};
void solution(vector<string> & ret) {
vector<Ref<string>> a;
vector<Ref<string>> b;
for (auto & c : ret) {
bool numeric = true;
for (auto const & d : c) {
if (!isdigit(d)) numeric = false;
}
if (numeric) a.emplace_back(c); else b.emplace_back(c);
}
sort(a.begin(), a.end());
sort(b.begin(), b.end());
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
vector<string> v;
string l;
getline(cin, l);
stringstream ss;
ss << l;
string s;
while (ss >> s) {
v.emplace_back(move(s));
}
solution(v);
bool first = true;
for (auto const & c : v) {
if (first) first = false; else cout.put(' ');
cout << c;
}
cout << '\n';
}
測(cè)試:
輸入
2 Banana 1 Apple 3 Pear
輸出
1 Apple 2 Banana 3 Pear
你的中文編碼是UTF8的?如果是查看一下你對(duì)應(yīng)的要匹配的中文的UTF8編碼,然后在regex正則表達(dá)式中使用對(duì)應(yīng)的UTF8編碼匹配。
你可以裝個(gè)瀏覽器版的插件,就不用裝在本機(jī)了。
//testgo.h
#ifdef __cplusplus
extern "C"{
#endif
extern long calladdr(long addr);
#ifdef __cplusplus
}
#endif
//testgo.cpp
#include "testgo.h"
long calladdr(long addr){
return addr;
}
//test.go
package main
// #include "testgo.h"
// #cgo LDFLAGS: ${SRCDIR}/testgo.so -lstdc++
import "C"
import "fmt"
import "unsafe"
type Work struct {
Name string
}
func main() {
data := &Work{Name: "aaa"}
ad := C.long(uintptr(unsafe.Pointer(data)))
addr := C.calladdr(ad)
newdata := (*Work)(unsafe.Pointer(uintptr(addr)))
fmt.Println("newdata is", newdata)
}
應(yīng)該可以滿足要求
locals=6,args(1個(gè)),short x(1個(gè)),double y(2個(gè)),double z(2個(gè))
dstore 4意思是從棧頂彈出2個(gè)字的值,因?yàn)槭莇型的,并把結(jié)果賦給第5和第6個(gè)local位置。
代碼0 0 0
為空
北大青鳥(niǎo)APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專(zhuān)業(yè)的國(guó)家
北大青鳥(niǎo)中博軟件學(xué)院創(chuàng)立于2003年,作為華東區(qū)著名互聯(lián)網(wǎng)學(xué)院和江蘇省首批服務(wù)外包人才培訓(xùn)基地,中博成功培育了近30000名軟件工程師走向高薪崗位,合作企業(yè)超4
中公教育集團(tuán)創(chuàng)建于1999年,經(jīng)過(guò)二十年潛心發(fā)展,已由一家北大畢業(yè)生自主創(chuàng)業(yè)的信息技術(shù)與教育服務(wù)機(jī)構(gòu),發(fā)展為教育服務(wù)業(yè)的綜合性企業(yè)集團(tuán),成為集合面授教學(xué)培訓(xùn)、網(wǎng)
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_(kāi)發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
曾工作于聯(lián)想擔(dān)任系統(tǒng)開(kāi)發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開(kāi)發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開(kāi)發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開(kāi)發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。