标签: parentheses

c#中的单独嵌套括号

我想在给定的字符串中从内到外取值。所以,如果我的字符串中有括号,首先我必须达到最深的括号。之后,我必须采用后面的括号如何组合前一个字符串。我必须沿着字符串进行这些过程。

示例输入:

C1 AND [C2 OR C3 OR [C4 OR [C5 AND C6] AND C7]] OR C8
Run Code Online (Sandbox Code Playgroud)

输出:

C5 AND C6
C4 OR [C5 AND C6] AND C7
C2 OR C3 OR [C4 OR [C5 AND C6] AND C7]
C1 AND [C2 OR C3 OR [C4 OR [C5 AND C6] AND C7]] OR C8
Run Code Online (Sandbox Code Playgroud)

c# regex split nested parentheses

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

在字符串 R 代码中查找嵌套括号的最大深度

我有一个问题来完成这个 R 代码。我们得到一个带有如下括号的字符串“( ((X)) (((Y))) )” 我们需要找到平衡括号的最大深度,如上例中的 4。由于“Y”被 4 个平衡括号包围。

如果括号不平衡,则返回 -1 我的代码如下所示:

current_max = 0
max = 0
def = function (S){
  n=S
  for (i in nchar(n))
    if (is.element('(',n[i]))
    {
      current_max <- current_max + 1   
    }
  if (current_max > max)
      {
        max <- current_max
      }
  else if (is.element(')',n[i]))
  {
    if (current_max > 0)
    {
      current_max <- current_max - 1
    }
    else
    {
      return -1
    }
  }
  if (current_max != 0)
  {
    return -1
  }
  return (max)
}
Run Code Online (Sandbox Code Playgroud)

但是当我调用函数 def("(A((B)))") …

nested r parentheses

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

检查java中括号的有效性

我试图找出给定的输入是否是有效的括号。输入字符串由 '(', ')', '{', '}', '[' 和 ']' 组成。
输入字符串在以下情况下有效:

1.左括号必须由相同类型的括号封闭。
2.左括号必须按正确的顺序闭合。3. 空字符串有效

但是,我下面使用递归的代码不适用于有效的情况。它应该转到基本情况(当输入为“”时),但转到 for 循环之后的 return 语句。

class Solution {

    public boolean validParen(String input) {

        if(input.isEmpty()) {
            return true;
        }

        else {
            for (int i = 0; i < input.length() - 1; i++) {
                if ((input.charAt(i) == '(' && input.charAt(i + 1) == ')') ||
                        (input.charAt(i) == '{' && input.charAt(i + 1) == '}') ||
                        (input.charAt(i) == '[' && input.charAt(i + 1) == ']')) {
                    input = input.substring(0, i) …
Run Code Online (Sandbox Code Playgroud)

java algorithm math recursion parentheses

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

为什么带括号和不带括号的乘法会有很大的不同?

如果我不加括号地乘以得到华氏度数,我得到的数与乘以它们时得到的数不同。这是为什么?

#include <stdio.h>

int main (){
    double userinput, fahr1, fahr2;

    printf("Enter a number in Cels ");
    scanf("%lf", &userinput);

    fahr1 = userinput*(9/5)+32;
    fahr2 = userinput*9/5+32;

    printf("fahr1 = %f and fahr2 = %f \n", fahr1, fahr2);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

#include <stdio.h>

int main (){
    double userinput, fahr1, fahr2;

    printf("Enter a number in Cels ");
    scanf("%lf", &userinput);

    fahr1 = userinput*(9/5)+32;
    fahr2 = userinput*9/5+32;

    printf("fahr1 = %f and fahr2 = %f \n", fahr1, fahr2);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c multiplication parentheses

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

用逗号表示preg_split,忽略括号,PHP

我必须拆分一个字符串,我想避免在括号内用逗号分隔它.那么我该如何实现呢?

例:

$string = "string1 (sString1, sString2,(ssString1, ssString2)), string2, string3";

result should be:

array(
   [0] => string1 (sString1, sString2,(ssString1, ssString2))
   [1] => string2
   [2] => string3
)
Run Code Online (Sandbox Code Playgroud)

php regex parentheses

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

Scala的方法重载:与使用或不使用括号定义的varargs和no-args方法的微妙功能差异背后的原因?

Scala(2.8.1)在处理重载方法时遇到了一个奇怪的问题,其中第一个是无参数,第二个采用可变数量的参数(0..N).测试代码:

class Test {
  def method1 = println("method1 invoked with zero args")
  def method1(args: Any*) = println("method1 with args " + args)

  def method2() = println("method2 invoked with zero args")
  def method2(args: Any*) = println("method2 with args " + args)
}

object Test {
  def main(args: Array[String]) {
    val t = new Test
    t.method1
    t.method1()
    t.method1(1,2,3)
    println
    t.method2
    t.method2()
    t.method2(1,2,3)
  }
}
Run Code Online (Sandbox Code Playgroud)

通过编译和运行它,输出是:

method1 invoked with zero args
method1 with args WrappedArray()
method1 with args WrappedArray(1, 2, 3)

method2 invoked …
Run Code Online (Sandbox Code Playgroud)

scala overloading parentheses

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

使用C++中的重载*运算符与括号结果相乘

所以我一直在用C++编写一个小的数学库,当处理一个标量乘以一个向量时,当我尝试执行这个操作时会遇到一些问题

Vect V2;
Vect V3;
float S;

Vect V1 = V2 + S * (V2 - V3);
Run Code Online (Sandbox Code Playgroud)

我在重载运算符*中收到的Vect值是一个新的Vect对象,而不是操作的(V2-V3)部分的结果.这是代码的其他相关部分.如果我按照调试操作,两个重载操作符本身可以正常工作,但不能一个接一个地工作.

Vect.h

Vect &operator - (const Vect &inVect);
friend const Vect operator*(const float scale, const Vect &inVect);
Run Code Online (Sandbox Code Playgroud)

Vect.cpp

Vect &Vect::operator - (const Vect &inVect)
{
    return Vect (this->x - inVect.x,this->y - inVect.y,this->z - inVect.z, 1);
}

const Vect operator*(const float scale, const Vect &inVect)
{
    Vect result;

    result.x = InVect.x * scale;
    result.z = InVect.y * scale;
    result.y = InVect.z * scale;
    result.w …
Run Code Online (Sandbox Code Playgroud)

c++ overloading vector parentheses

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

setInterval中的Javascript函数

我有以下代码:

var foo=5;
var los= function (){
    alert(foo);};
setInterval(los, 1000);
Run Code Online (Sandbox Code Playgroud)

哪个工作正常.

如果我将其更改为:

var los= function (){
    alert(foo);};
setInterval(los(), 1000);
Run Code Online (Sandbox Code Playgroud)

它只在控制台中执行一次且没有错误.有人可以解释一下,为什么当我lossetInterval功能中包括胃肠功能后会发生这种情况?

javascript function parentheses setinterval

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

如何在create table Sql查询中的列名中设置括号

我想在SQL Server2012中创建一个表,其列名包括括号as

create table temp_sp 
( 
    logtime datetime,
    vcs_api varchar,
    L3(S1)Status varchar,
    L3(S2)Status varchar,
    beam_current real,
    beam_energy real,
    st1_vs1_bag1_rb real,
    ring_avg_pressure real
)
Run Code Online (Sandbox Code Playgroud)

但是当我使用括号时L3(S1)Status,L3(S2)Status我得到一个错误

'('.'''''''或'''附近的语法不正确.**

怎么解决?

sql-server columnname parentheses

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

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