免责声明:我是新来编写正则表达式的人,所以唯一的问题可能是我缺乏经验。
我正在尝试编写一个正则表达式,该表达式将在括号内找到数字,并且我希望数字和括号都包含在选择中。但是,我只希望它在字符串的开头匹配。因此,在下面的文本中,我希望它得到(10),而不是(2)或(图50)。
(10) Joystick Switch - Contains control switches (Figure 50)
Two (2) heavy lifting straps
Run Code Online (Sandbox Code Playgroud)
到目前为止,我有(\(\d+\))(10)但也有(2)。我知道^应该与字符串(或行)的开头匹配,但我无法使其工作。在这里和其他站点上,我都看过很多类似的问题,但是只发现了部分解决方案(在括号内查找内容,仅在字符串的开头找到数字等),但还不太清楚能够将它们组合在一起工作。
我正在使用它在CAT工具中(针对翻译中的您)创建过滤器,这意味着不涉及其他编码语言。本质上,我一直在使用RegExr来测试我编写的所有其他表达式,而且效果很好。
我有以下功能:
digits :: Int -> [Int]
digits n = go n []
where go num acc
| num < 10 = num : acc
| otherwise = go (div num 10) (mod num 10 : acc)
Run Code Online (Sandbox Code Playgroud)
是否可以用otherwise表达式替换括号中的括号$?
我刚刚开始学习C++,我正在尝试使Thread类具有Java Thread类的基本功能.我正在尝试做的是创建一个你继承的类,编写一个Run方法(在基类中是纯虚拟的)创建一个子类的对象,在它上面调用start方法并且你有线程.
问题是,在我使用C++的方式中,调度没有正确完成 - 就像Run函数不是虚函数一样,调用了基类的Run方法.
这是标题的代码
#ifndef _THREAD_H_
#define _THREAD_H_
#include <pthread.h>
class Thread {
public:
Thread();
void Start();
~Thread();
protected:
virtual void Run() = 0;
private:
static void *RunWrapper(void *);
pthread_t thread;
};
#endif
Run Code Online (Sandbox Code Playgroud)
实施
#include "thread.h"
#include <pthread.h>
Thread::Thread() {
}
void Thread::Start() {
pthread_create(&thread, NULL, Thread::RunWrapper, (void *) this);
}
void *Thread::RunWrapper(void *arg) {
Thread *t = (Thread *) arg;
t->Run();
return arg;
}
Thread::~Thread() {
pthread_join(thread, NULL);
}
Run Code Online (Sandbox Code Playgroud)
而实际上试图做某事的文件
#include <iostream>
#include "thread.h"
class MyThread : …Run Code Online (Sandbox Code Playgroud) String您建议使用哪种方式转换Java对象?为什么?
例如,假设我们有:
StringBuilder sb = new StringBuilder();
我们可以通过String两种方式将其转换为.第一:
sb.toString();
Run Code Online (Sandbox Code Playgroud)
第二:
sb + "";
Run Code Online (Sandbox Code Playgroud) 我有一个字符串,有三个字母,1,2,X.有时字符串可以是12,或1X,或2X ..等.
我想根据输入字母的位置添加" - ".例如,如果我得到1,结果应该是1--,如果我得到X,结果应该是-X,如果我得到2X,结果应该是-2X.
我的方法是使用2 ^ n选择的状态机,但我正在寻找一个聪明的apporach和更好的apporach.
更多例子
Input 1 2 X 2X
Ouput 1-- -2- --X -2X
Run Code Online (Sandbox Code Playgroud) 我们有N整数计数器,最初显示为0.操作:
int getMax() - 返回计数器显示的最高值.
void increment(int i)- 递增计数器的值i.
void zero() - 为所有计数器设置零值.替代名称flood(),也许这个名字对你有帮助.
当前实现这些操作和底层数据结构,知道我们希望这些操作尽可能快.
这是我的面试问题.由于我的记忆力不足,我说出一些错误的可能性很小,但我尽力了.也许它类似于一些众所周知的问题?(我希望.)
据我所知,所有操作都可以在O(1)中完成......其中一个操作是"懒惰的"(可能increment)......即在一个通话时刻它什么都不做,但后来当用户要求价值getMax()- 它工作.
有人可以解释为什么.exe程序没有运行尽管turbo c ++编译器没有显示任何错误?
编译器没有显示任何错误
#include <stdio.h>
#include <conio.h>
int main ()
{
int choice;
float num, result;
printf("Select your choice\n");
printf("Press 1 for conversion from milligrams to grams\n");
printf("Press 2 for conversion from decigrams to grams\n");
printf("Press 3 for conversion from centigrams to grams\n");
printf("Press 4 for conversion from kilograms to grams\n");
printf("Press 5 for conversion from ounce to grams\n");
printf("Press 6 for conversion from pounds to grams\n");
printf("Press 7 for conversion from ton to grams\n");
switch(choice) //i thought the …Run Code Online (Sandbox Code Playgroud) 我似乎无法弄清楚为什么以下代码将无法编译.我在线上说错了:if ((number % 2) == 0) {.错误消息显示:"非法字符".该程序应该采取数字n.如果n ==为1,则程序停止.如果n是奇数,那么新的n ==(n*3)+1.如果n是偶数,则新n == n/2.
import java.util.Scanner;
import java.lang.Math.*;
public class HasseAlgoritme {
public static void main(string [] args) {
Scanner tastatur = new Scanner(System.in);
System.out.print("Input the first starting number");
int number = tastatur.next();
while (number != 1) {
System.out.print(number);
if ((number % 2) == 0) {
System.out.println(number);
}
else {
number = (number*3)+1;
System.out.print(number);
}
}
}}
Run Code Online (Sandbox Code Playgroud)