LintCode(容易)二进制中有多少个1(错误集)

  • Post author:
  • Post category:其他


错误代码:

bug1:

int main(int num) {
    stringstream ss;
    ss << num; cout << num;
    string s1 = ss.str();  int timesof1 = 0;
    for (auto c : s1){
        if (c == '1'){
            timesof1++;
        }
    }
    //cout<< timesof1;
    system("pause");
}

就以上代码,发现:当没有向控制台输入num的值时,num的值默认为1.

然后百度:



版权声明:本文为Jang1996原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。