鍍金池/ 問答/ C++問答
祈歡 回答

好吧,是自己反傻了,原來finish標(biāo)識設(shè)置為1之后,再次start的時候沒有重新置為0...

背叛者 回答

你都對需求進(jìn)行交付了!

可以重構(gòu),但是你要考慮當(dāng)下適不適合重構(gòu)!

你覺得有很大問題需要重構(gòu),那你要跟領(lǐng)導(dǎo)商量啊

來守候 回答

查詢隊(duì)列指的是什么

在官方文檔的Introduction部分其實(shí)就講到了,文檔傳送門

  • Every method you invoke on a connection is queued and executed in sequence.
  • Closing the connection is done using end() which makes sure all remaining queries are executed before sending a quit packet to the mysql server.

舉例,下面的兩個調(diào)用,在內(nèi)部是排隊(duì)執(zhí)行的。

connection.query('SELECT * FROM hello');
connection.query('SELECT * FROM world');

end、destroy的區(qū)別

兩者的區(qū)別很明顯,還是以前面的代碼為例子。

1、connection.end():把查詢1、查詢2順利執(zhí)行完,得到查詢結(jié)果后,斷開mysql服務(wù)器的連接。
2、connection.destryo():直接斷開連接,不管還有多少查詢沒執(zhí)行完。

connection.query('SELECT * FROM hello'); // 查詢1
connection.query('SELECT * FROM world'); // 查詢2

js
data() {return {content: '<a href="xxx">點(diǎn)擊進(jìn)入</a> <span>Hello 你好</span>'}}`
模板
<div>{{content}}</div>

失魂人 回答

第一種語境下,a(i);是一個語句(statement),此時編譯器會把它解析成變量聲明,由此局部變量i與函數(shù)參數(shù)重名。

根據(jù)語法,它可以被解釋成函數(shù)式顯式類型轉(zhuǎn)換或者聲明,存在二義性。標(biāo)準(zhǔn)約定將其解釋成聲明。

9.8.1 There is an ambiguity in the grammar involving expression-statements and declarations: An expression statement with a function-style explicit type conversion (8.2.3) as its leftmost subexpression can be indistinguishable from a declaration where the first declarator starts with a (. In those cases the statement is a declaration.

你給出的第二種語境下,a(i)是ctor-initializer,不存在表達(dá)式、聲明二義性。

瘋子范 回答

當(dāng)然有意義。
你覺得你用不到,很多時候是框架幫你做了這些事情。
我舉幾個例子

  • 怎么判斷是 ajax 請求,是不是需要 http header 的信息
  • 怎么判斷請求是 post、get、put ?
  • 怎么設(shè)置 cookie

誠然,其實(shí)不用這些標(biāo)準(zhǔn)也能實(shí)現(xiàn)很多東西,但是我們?yōu)槭裁凑f面向接口編程,就是不需要知道實(shí)現(xiàn)細(xì)節(jié),也能很好的使用。

撥弦 回答

你確定你編譯出來了嗎?cout << *p;你都沒加分號。另外#include <iostream>using namepspace std;你加了嗎?還有C++的main一定要return一個整型的,而不是void

以下代碼我已經(jīng)測試過了,會輸出55。

#include <iostream>

using namespace std;

class base {
    private:
        int x;
    public:
        void setx(int a) {x = a;}
        int getx() {return x;}
};

int main() {
    int * p;
    base a;
    a.setx(55);
    p = new int(a.getx());
    cout << *p;
    return 0;
}
萌二代 回答

因?yàn)?code>&&的優(yōu)先級比||高,所以你給的例子去掉括號也不影響結(jié)果。加上括號只是使代碼更易讀。

但是有時候括號是必須的,比如a && (b || c),如果去掉括號結(jié)果就變成了(a && b) || c

拼未來 回答

0 荷葉,n 柱子這么想,假設(shè)河中有 n 個柱子:

  • n = 0 時,至多有 1 只青蛙直接跳到 R 柱,這個不用解釋
  • n = 1 時,由于河中多了一個落腳的地方,那么這個柱子(A 柱)可以先從 L 柱至多跳 1 只青蛙下來,然后這個 A 柱和 L 柱總共至多可以跳 2 只青蛙至 R 柱
  • n = 2 時,由于河中又多了一個柱子(B 柱),那么可以先從 L 柱跳 1 只青蛙到 B 柱,之后 A 柱的青蛙也可以跳到 B 柱上,然后 B 柱上有 2 只青蛙,然后 L 柱再跳 1 只青蛙至 A 柱,之后無法再繼續(xù)跳更多青蛙,最后 L 柱往 R 柱跳 1 只,A 柱跳 1 只,B 柱 跳 2 只(這里需要先在 A 柱跳完后往 A 跳一次,再跳 R 柱),總共 4 只
  • n = 3 時,其實(shí)基本可以看出遞歸的規(guī)律了,比如接著上面的情況,多了一個 C 柱,那么這個柱子可以先從 L 柱跳一只青蛙下來,之后河中其余柱子上的青蛙均跳至 C 柱,C 柱上的青蛙就等于 1(A柱青蛙) + 2(B柱青蛙) + 1(L柱新跳下來的青蛙)= 4,然后 B 柱按上一種情況可知是 2,A 柱是 1,最終至多跳 1 + 2 + 4 + 1 = 8 只
  • n = 4 時,按上面的規(guī)律就能知道,D 柱上先從 L 柱跳 1 只,然后其余柱子的青蛙跳過來,總共 8 只,然后至多跳 1 + 2 + 4 + 8 + 1 = 16 只
  • ...(略)

這個過程似乎和漢諾塔很像,但是不是漢諾塔。

最后在這個基礎(chǔ)之上來考慮荷葉不為 0 的情況,由于荷葉上只能跳 1 只青蛙,相當(dāng)于只是將問題的規(guī)模放大了,所以最后答案是荷葉數(shù)量 + 1(直接跳到 R 柱的那個青蛙) 之后按河中柱子的個數(shù)依次乘以 2。

苦妄 回答

在/root/.bitcoin/下面創(chuàng)建配置文件bitcoin.conf

cp ./contrib/debian/examples/bitcoin.conf /root/.bitcoin/

直接運(yùn)行bitcoind
bitcoind

查看端口8332
lsof -i:8332
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
bitcoind 8331 root 9u IPv6 308456 0t0 TCP *:8332 (LISTEN)

懷中人 回答

做oj不要太依賴調(diào)試工具(比如單步debugger), 一般依次有以下解決方法:

  1. 肉眼
  2. printf打log, 比如輸出中間變量, 看哪裏出問題.
  3. 推倒重新寫一邊
  4. 如果是爲(wèi)了打比賽, 且比賽環(huán)境提供gdb, 亦或是cb/devcpp, 那麼熟悉相應(yīng)環(huán)境來debug.

具體到你的這份代碼, 補(bǔ)完頭文件是可以在gcc上運(yùn)行的. 如果你本地補(bǔ)完依然不行, 請貼出你的環(huán)境(編譯器)以及出錯信息.

另, 提供幾點(diǎn)出錯可能性:

  1. 線上c的環(huán)境是c89/90或者是ansi c, 那麼bool是不能用的. 因爲(wèi)c的bool是c99才有的, 如果沒有#include<stdbool.h>, 那麼需要_Bool做聲明, #include<stdbool.h>中的話做了typedef, 可以直接寫bool.
  2. 你可能在本地是用然後g++編譯cpp而不適.c, 那麼在本地請使用gcc編譯.c. 或者線上環(huán)境也切成c++, 反正無論如何保持本地和線上環(huán)境一致, 切記c和c++是兩門完全不同的語言, 不要混爲(wèi)一彈, 哪怕碰巧同一份文件有時候都能通過編譯.
  3. 你使用了#include <bits/stdc++.h>, 所以線上粘貼時漏了頭文件.

最後, 標(biāo)籤中只保留c和c++中的一個, 不要都貼.

撥弦 回答
#include <iostream>
#include <string>

const int Asize = 20;
int main()
{
    using namespace std;
    char line[Asize];
    cout << "Type, and I shall repeat.\n";

    int idx=0;
    char temp{};
    do{
        cin.get(temp);
        line[idx++] = temp;
        if(idx==Asize-1){
            idx=0;
        }
    }while(temp!='.');

    cout<<string(line);

    cout << "\nPlease excuse the slight confusion.\n";
    return 0;
}
柚稚 回答

第一個媒體查詢后面少了個大括號,現(xiàn)在主流的編輯器應(yīng)該都會提示語法錯誤,正確的CSS代碼如下:

@media screen and (min-width:1080px) {
    .outer{
        width:1208px;
        height:302px;
        border:solid 5px red;
        margin:0 auto;
    }
    .inner{
        width:300px;
        height:300px;
        border:dashed 1px blue;
        float:left;
        text-align:center;
        line-height:300px;
        font-size:40px;    
    }
}

@media screen and (max-width:1080px) {
    .outer{
        width:100%;
        min-width:404px;
        height:604px;
        border:solid 5px red;
        margin:0 auto;
    }
    .inner{
        width:49.5%;
        height:300px;
        border:dashed 1px blue;
        float:left;
        min-width:i200px;
        text-align:center;
        line-height:300px;
        font-size:30px;
    }
}
笑忘初 回答

你把這個看成一個數(shù)學(xué)問題
階乘是什么?
f(1) = 1
f(n) = n * f(n-1)
所以就是

def f(n):
  if n <= 0:
    return 0
  if n == 1:
    return 1
  return n * f(n-1)
涼心人 回答

ios打包需要xcode這個工具來打包,先用cordova生成文件夾,然后把ios這個文件夾移動到mac,用xcode這個工具打開文件夾,https://www.jianshu.com/p/019... 可以看一下這篇文章,寫的挺詳細(xì)的

選擇 回答
    public function msgId($spid, $sqid)
    {
        $timeStr = time();
        //echo bindec(sprintf("%04s%05s%05s%06s%06s%022s%016s",decbin(date('m', $timeStr)),decbin(date('d', $timeStr)),decbin(date('H', $timeStr)),decbin(date('i', $timeStr)),decbin(date('s', $timeStr)),decbin($spid), decbin($sqid)));
        return bindec(sprintf("%04s%05s%05s%06s%06s%022s%016s",decbin(date('m', $timeStr)),decbin(date('d', $timeStr)),decbin(date('H', $timeStr)),decbin(date('i', $timeStr)),decbin(date('s', $timeStr)),decbin($spid), decbin($sqid)));
    }

    $this->msgId('600010','2');

在這里面給你糾正一下思路
第一: 64里面只能存0-1之間的數(shù)值,也就是說都是2進(jìn)制數(shù)據(jù)
所以拼接一下2進(jìn)制數(shù)據(jù)就好了

月份(1-12)(【0001-1100】區(qū)間 4位)decbin(date('m', $timeStr))
日(1-31)(【00001-11111】區(qū)間 5位)decbin(date('d', $timeStr))
時(1-24)(【00001-11000】區(qū)間 5位)decbin(date('H', $timeStr))
分(1-59)(【000001-111011】區(qū)間 6位)decbin(date('i', $timeStr))
秒(1-59)(【000001-111011】區(qū)間 6位)decbin(date('s', $timeStr))
網(wǎng)關(guān)代碼(【0~0 - 1~1】22位)decbin($spid1)
// (如果這個網(wǎng)關(guān)代碼是22位0和1組成就不用decbin,本身就是2進(jìn)制了,如果不是的話,就變成二進(jìn)制)
序列號(區(qū)間 16位)decbin($spid2)

網(wǎng)關(guān)代碼多少位我沒洗數(shù),序列號,什么的位數(shù)你自己調(diào)就行了%04d%06d%05d%06d%06d【%021d%016d】<-這里 如果沒算錯的話是4+5+5+6+6+22+16應(yīng)該是64位了,那么這64位是一個2進(jìn)制的字符串,用bindec()轉(zhuǎn)換成十進(jìn)制的數(shù)值,存進(jìn)數(shù)據(jù)庫里面,那么數(shù)據(jù)庫存貯的2進(jìn)制數(shù)據(jù)就是符合你要的規(guī)定了,而且10進(jìn)制數(shù)據(jù),8位,64字節(jié),完美

變量名用點(diǎn)心$spid, $sqid 我以為是一個

下面這種方法也是簡單,邏輯上不好理解,但是還是挺簡單的,學(xué)習(xí)了

$messageId = 0;
$messageId |= $m << 60;
$messageId |= $d << 55;
$messageId |= $h << 50;
$messageId |= $i << 44;
$messageId |= $s << 38;
$messageId |= $spid << 16;
$messageId |= $sqid & 0xff;
echo $messageId
離夢 回答

JS:

import lineChart from '../lineChart'
export default {
  name: 'demo',
  components: {
    'line-chart': lineChart 
  },
  // ...
}

HTML:

<template>
    <div>
        <line-chart></line-chart>
    </div>
</template>

基礎(chǔ)組件的自動化全局注冊

胭脂淚 回答

在編譯時加上參數(shù)就行了

    $ make ARCH=arm CROSS_COMPILE=arm-linux-gnueabi- 
愛礙唉 回答

不用 inplace (直接分成兩個數(shù)組排序,再合并) 的話就太簡單了,要 inplace 的話其實(shí)也可以不用手寫 iterator,手寫一個 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';
}

測試:

輸入

2 Banana 1 Apple 3 Pear

輸出

1 Apple 2 Banana 3 Pear