sub

js字符串函数

隐身守侯 提交于 2019-12-01 06:28:54
js字符串函数 JS自带函数2477203708 concat 将两个或多个字符的文本组合起来,返回一个新的字符串。 var a = "hello"; var b = ",world"; var c = a.concat(b); alert(c); //c = "hello,world" indexOf 返回字符串中一个子串第一处出现的索引(从左到右搜索)。如果没有匹配项,返回 -1 。 var index1 = a.indexOf("l"); //index1 = 2 var index2 = a.indexOf("l",3); //index2 = 3 charAt 返回指定位置的字符。 var get_char = a.charAt(0); //get_char = "h" lastIndexOf 返回字符串中一个子串最后一处出现的索引(从右到左搜索),如果没有匹配项,返回 -1 。 var index1 = lastIndexOf('l'); //index1 = 3 var index2 = lastIndexOf('l',2) //index2 = 2 match 检查一个字符串匹配一个正则表达式内容,如果么有匹配返回 null。 var re = new RegExp(/^\w+$/); var is_alpha1 = a.match(re); //is_alpha1

Attention is all you need 详细解读

╄→尐↘猪︶ㄣ 提交于 2019-12-01 06:03:35
  自从 Attention 机制在提出之后,加入 Attention 的 Seq2Seq 模型在各个任务上都有了提升,所以现在的 seq2seq 模型指的都是结合 rnn 和 attention 的模型。传统的基于 RNN 的 Seq2Seq 模型难以处理长序列的句子,无法实现并行,并且面临对齐的问题。 所以之后这类模型的发展大多数从三个方面入手: · input 的方向性: 单向 -> 双向 · 深度: 单层 -> 多层 · 类型: RNN -> LSTM GRU 但是依旧收到一些潜在问题的制约,神经网络需要能够将源语句的所有必要信息压缩成固定长度的向量。这可能使得神经网络难以应付长时间的句子,特别是那些比训练语料库中的句子更长的句子;每个时间步的输出需要依赖于前面时间步的输出,这使得模型没有办法并行,效率低;仍然面临对齐问题。 再然后 CNN 由计算机视觉也被引入到 deep NLP 中, CNN 不能直接用于处理变长的序列样本但可以实现并行计算。完全基于 CNN 的 Seq2Seq 模型虽然可以并行实现,但非常占内存,很多的 trick ,大数据量上参数调整并不容易。 本篇文章创新点在于抛弃了之前传统的 encoder-decoder 模型必须结合 cnn 或者 rnn 的固有模式,只用 Attention

Leetcode(3)无重复字符的最长子串

时间秒杀一切 提交于 2019-11-30 23:51:33
Leetcode(3)无重复字符的最长子串 [题目表述]: 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 第一种方法:暴力 执行用时:996 ms; 内存消耗:12.9MB 效果:太差 class Solution(object): def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ Maxsize=0 res='' if len(s)==1:Maxsize=1 for i in range(len(s)): for j in s[i:len(s)]: if j not in res:res+=j else: break Maxsize=max(Maxsize,len(res)) res='' return Maxsize 学习 利用一个空串来存储子串 for对迭代对象的使用 第二种方法:一个for加切片操作 执行用时:60 ms; 内存消耗:12.1MB 效果:非常好 class Solution: def lengthOfLongestSubstring(self, s): """ :type s: str :rtype: int """ res = '' maxlen = 0 for i in s: if i not in res: res += i else:

CSCI 3120 Operating Systems

偶尔善良 提交于 2019-11-30 22:52:01
CSCI 3120 Operating Systems Assignment 2: Multithreaded Sorting Due: 16:00, Oct. 25, 2019 - Teaching Assistants: o Lauchlan Toal (lc790935@dal.ca), o Patricia Kibenge-MacLeaod (p.kibenge@dal.ca) o Hui Huang (huihuang@dal.ca) - Help Hours at CS Learning Center (2nd Floor of Goldberg Building): o Tuesdays: 1pm-3pm, Hui Huang o Thursdays: 2pm-4pm, Patricia Kibenge-MacLeaod o Fridays: 12pm-2pm, Lauchlan Toal 1. Assignment Overview In this assignment, you need to design and implement a C program that utilizes multithreading to accomplish the task of integer sorting. 2. Important Note There is a

【LeetCode】36. Valid Sudoku

亡梦爱人 提交于 2019-11-30 22:07:01
Difficulty: Medium More: 【目录】LeetCode Java实现 Description https://leetcode.com/problems/valid-sudoku/ Determine if a 9x9 Sudoku board is valid. Only the filled cells need to be validated according to the following rules: Each row must contain the digits 1-9 without repetition. Each column must contain the digits 1-9 without repetition. Each of the 9 3x3 sub-boxes of the grid must contain the digits 1-9 without repetition. A partially filled sudoku which is valid. The Sudoku board could be partially filled, where empty cells are filled with the character '.' . Example 1: Input: [ ["5","3",".",".

c语言实现串

心已入冬 提交于 2019-11-30 21:29:42
串 (string)是由零个或者多个字符组成的有限序列,又称字符串 一般表示为 S=“ a 1 a 2 a 3 a 4 . . . . . a n ” 其中S 是串名,双引号串起来的是串值,(有些书用单引号)引号本身不属于串值,a1 可以是字母 数字 符号 ,串中的n称为串的长度,零个字符的串称为空串(null string)表示为““””(4个引号) 或者“Φ” 表示,串长度为零。 串中任意个数连续字符组成的串都是主串的字串 例如 S="absjasdaasjlask" (主串) s="sja" ,s="bsjasd" s=" Φ",等等都是主串的字串 (空串是任何串的字串) 因此 在串的结构体中 需要存储串的空间 本次使用数组(也可malloc在堆内存中申请)需要一个记载串长度的整型 length (串中长度不包括'\0') typedef struct Str { char elem[SIZE]; int length;//没有'\0' }Str; 对串的操作函数有 void StrAssign(Str *s,const char *chars) ;// 初始化串 void StrCpy(Str *s,Str *t);// 把t 串拷贝到s 串 bool IsEmpty(Str *s);// 判断是否空串 int GetLength(Str *s);// 返回串的长度

vue数据事件修饰符

戏子无情 提交于 2019-11-30 18:05:52
vue数据在嵌套div的时候会产生冒泡,既点击了下层的div标签,上层也会出发点击效果。如何防止呢,使用click.stop即可 <div id="app"> <div class="parent" @click="parentClick"> <div class="sub" @click.stop="subClick" > <div class="child" @click.stop="childClick"> </div> </div> </div> </div> 阻止默认事件 <a href="http://www.baidu.com" @click.prevent="aClick" >baidu</a> click.self 只有在自己身上触发的时候才执行 <div id="app"> <div class="parent" @click="parentClick"> <div class="sub" @click.self="subClick" > <div class="child" @click.stop="childClick"> </div> </div> </div> <a href="http://www.baidu.com" @click.prevent="aClick" >baidu</a> </div> edit by cherrydot 来源:

2.变量

空扰寡人 提交于 2019-11-30 16:57:38
import tensorflow as tf # 定义一个变量 x = tf.Variable([1,2]) # 定义一个常量 a = tf.constant([3,3]) # 减法op sub = tf.subtract(x, a) # 加法op add = tf.add(x,sub) # 所有变量初始化 init = tf.global_variables_initializer() with tf.Session() as sess: # 执行变量初始化 sess.run(init) print(sess.run(sub)) print(sess.run(add)) 来源: https://www.cnblogs.com/liuwenhua/p/11605297.html

字符串函数参数传入传出(字符串反转)

三世轮回 提交于 2019-11-30 16:49:53
/*** strstr.c ***/ #include<stdio.h> #include<string.h> //求字符串p中abcd出现的次数 //自定义函数接口完成业务函数和main函数分开 int getCount(char *mystr,char *sub,int *ncount) { int ret = 0; if(mystr == NULL || sub == NULL || ncount == NULL) { ret = -1; printf("one of point is NULL\n"); return ret; } int tmpCount = 0; char *p = mystr; //不要轻易改变形参的值 do { p = strstr(p,sub); if(p != NULL) { tmpCount++; p = p +strlen(sub); } else { break; } }while(*p != '\0'); *ncount = tmpCount; //间接赋值是指针存在的最大意义 return ret; } int main() { int ret = 0; char *p = "abcd11122abcd3333abcd3456abc"; int count = 0; char sub[] = "abcd"; ret = getCount

re模块

六月ゝ 毕业季﹏ 提交于 2019-11-30 16:31:28
目录 正则表达式: 匹配过程: 贪婪模式及非贪婪模式: 反斜杠困扰: re模块中的功能函数: re.match(pattern, string[, flags]): re.search(pattern, string[, flags])函数 re.findall(pattern, string[, flags])函数(常用) e.split(pattern, string[, maxsplit])函数 re.sub(pattern, repl, string[, count])函数 re.subn(pattern, repl, string,[, count][, flags])函数 分组函数: 注意事项: 正则表达式: --字符串匹配,进行字符串处理 匹配过程: 依次拿出表达式和文本中的字符比较,如果每一个字符都能匹配,则匹配成功;一旦有匹配不成功的字符则匹配失败 一, 贪婪模式及非贪婪模式: --匹配尽可能多的字符;非贪婪的则相反,总是尝试匹配尽可能少的字符 反斜杠困扰: 需要匹配文本中的字符 \ ,那么使用编程语言表示的正则表达式里将需要4个反斜杠 \\\\ :前两个和后两个分别用于在编程语言里转义成反斜杠,转换成两个反斜杠后再在正则表达式里转义成一个反斜杠 ()元字符 (分组) 也就是分组匹配,()里面的为一个组也可以理解成一个整体 如果()后面跟的是特殊元字符如 (abc