小编Mic*_* M.的帖子

为什么0 [0]语法上有效?

为什么这行在javascript中有效?

var a = 0[0];
Run Code Online (Sandbox Code Playgroud)

在那之后,aundefined.

javascript

119
推荐指数
5
解决办法
6639
查看次数

用sed划分一行中的数字

我有一条线:

CITY;+41119;-754831
Run Code Online (Sandbox Code Playgroud)

我想将这两个数字除以10000得到这一行:

CITY;4.1119;-75.4831
Run Code Online (Sandbox Code Playgroud)

我已经尝试了以下sed命令,但它没有做任何事,出了什么问题?

sed 's/(.*;.*)([0-9]{4};.*)([0-9]{4})/\1\.\2\.\3/g'
Run Code Online (Sandbox Code Playgroud)

regex awk sed

3
推荐指数
1
解决办法
1417
查看次数

最接近2的力量

给定无符号整数a(小于或等于1024),我需要找到p满足以下条件的数字:

  • 最低 p >= a
  • p 是2的力量

我确信有一个更好的解决方案,使用按位运算符.
你有更好的解决方案吗?

unsigned int closest_pow2(unsigned int a)
{
  if (a == 0 || a > 1024) return 0; //error, never happen
  if (a == 1) return 1;
  if (a == 2) return 2;
  if (a <= 4) return 4;
  if (a <= 8) return 8;
  if (a <= 16) return 16;
  if (a <= 32) return 32;
  if (a <= 64) return 64;
  if (a <= 128) …
Run Code Online (Sandbox Code Playgroud)

c

3
推荐指数
1
解决办法
635
查看次数

为什么属性名称中的引号会引发错误?

当我执行一个 包含node.js的文件时{"test":1},会引发一个SyntaxError:

(function (exports, require, module, __filename, __dirname) { {"test":1}
                                                                     ^
SyntaxError: Unexpected token :
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3
Run Code Online (Sandbox Code Playgroud)

但是{test:1}(没有引号)或var t = {"test":1}工作正常.

我执行包含运行代码的文件:node test.js.

为什么?

javascript json node.js

1
推荐指数
1
解决办法
75
查看次数

c ++控制台程序中strcpy函数的异常

strcpy()中的异常;

void recid(string str,int *begin, int *end)
{
  char *f,*str2;

  const char c1[2]=":",c2[2]="-";
  strcpy(str2,str.c_str());
  f=strtok(str2,c1);
  f=strtok(NULL,c2);
  *begin=atoi(f);
  f=strtok(NULL,c2);
  *end=atoi(f);
}
Run Code Online (Sandbox Code Playgroud)

你能帮我解决一下吗?

c++ exception strcpy

-3
推荐指数
1
解决办法
374
查看次数

标签 统计

javascript ×2

awk ×1

c ×1

c++ ×1

exception ×1

json ×1

node.js ×1

regex ×1

sed ×1

strcpy ×1