1.字符串
string 的定义
string 的初始化
string 的长度
string 的元素的访问
数组
迭代器
元素的操作
insert()
erase()
clear()
运算符
连接 +
比较运算符
判断是否相等
常用函数
find()
substr()
2.字符串处理
写个算法,对2个小于1000000000的输入,求结果。 特殊乘法举例:123 * 45 = 1*4 +1*5 +2*4 +2*5 +3*4+3*5
两个小于1000000000的数
输入可能有多组数据,对于每一组数据,输出input中的两个数按照题目要求的方法进行运算后得到的结果。
在情报传递过程中,为了防止情报被截获,往往需要对情报用一定的方式加密,简单的加密算法虽然不足以完全避免情报被破译,但仍然能防止情报被轻易的识别。我们给出一种最简的的加密方法,对给定的一个字符串,把其中从a-y,a-y的字母用其后继字母替代,把z和z用a和a替代,则可得到一个简单的加密字符串。
读取这一行字符串,每个字符串长度小于80个字符。
对于每组数据,输出每行字符串的加密字符串。
julius caesar曾经使用过一种很简单的密码。 对于明文中的每个字符,将它用它字母表中后5位对应的字符来代替,这样就得到了密文。 比如字符a用f来代替。如下是密文和明文中字符的对应关系。 密文 a b c d e f g h i j k l m n o p q r s t u v w x y z 明文 v w x y z a b c d e f g h i j k l m n o p q r s t u 你的任务是对给定的密文进行解密得到明文。 你需要注意的是,密文中出现的字母都是大写字母。密文中也包括非字母的字符,对这些字符不用进行解码。
输入中的测试数据不超过100组。每组数据都有如下的形式,而且各组测试数据之间没有空白的行。
一组测试数据包括三部分:
起始行 :一行,包括字符串 "start"
密文:一行,给出密文,密文不为空,而且其中的字符数不超过200
结束行 : 一行,包括字符串 "end"
在最后一组测试数据之后有一行,包括字符串 "endofinput"。
对每组数据,都有一行输出,给出密文对应的明文。
统计一个给定字符串中指定的字符出现的次数。
测试输入包含若干测试用例,每个测试用例包含2行,第1行为一个长度不超过5的字符串,第2行为一个长度不超过80的字符串。注意这里的字符串包含空格,即空格也可能是要求被统计的字符之一。当读到'#'时输入结束,相应的结果不要输出。
对每个测试用例,统计第1行中字符串的每个字符在第2行字符串中出现的次数,按如下格式输出:
c0 n0
c1 n1
c2 n2
...
其中ci是第1行中第i个字符,ni是ci出现的次数。
输入一行字符串,计算其中a-z大写字母出现的次数
案例可能有多组,每个案例输入为一行字符串。
对每个案例按a-z的顺序输出其中大写字母出现的次数。
在 skew binary 表示中,第 k 位的值 x[k] 表示 x[k]×(2^(k+1)-1)。每个位上的可能数字是 0 或 1,最后面一个非零位可以是 2,例如,10120(skew) = 1×(2^5-1) + 0×(2^4-1) + 1×(2^3-1) + 2×(2^2-1) + 0×(2^1-1) = 31 + 0 + 7 + 6 + 0 = 44。前十个 skew 数是 0、1、2、10、11、12、20、100、101、以及 102。
输入包括多组数据,每组数据包含一个 skew 数。
对应每一组数据,输出相应的十进制形式。结果不超过 2^31-1。
输入一个字符串,以回车结束(字符串长度<=100)。该字符串由若干个单词组成,单词之间用一个空格隔开,所有单词区分大小写。现需要将其中的某个单词替换成另一个单词,并输出替换之后的字符串。
多组数据。每组数据输入包括3行, 第1行是包含多个单词的字符串 s, 第2行是待替换的单词a,(长度<=100) 第3行是a将被替换的单词b。(长度<=100) s, a, b 最前面和最后面都没有空格。
每个测试数据输出只有 1 行, 将s中所有单词a替换成b之后的字符串。
对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。 在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\t')、回车符('\r')、换行符('\n')。
输入一行:待处理的字符串(长度小于100)。
可能有多组测试数据,对于每组数据,
输出一行:转换后的字符串。
求2个浮点数相加的和。题目中输入输出中出现浮点数都有如下的形式: p1p2...pi.q1q2...qj 。对于整数部分,p1p2...pi是一个非负整数;对于小数部分,qj不等于0。
对于每组案例,每组测试数据占2行,分别是两个加数。
每组案例是n行,每组测试数据有一行输出是相应的和。
输出保证一定是一个小数部分不为0的浮点数
对于一个字符串,将其后缀子串进行排序,例如grain 其子串有: grain rain ain in n 然后对各子串按字典顺序排序,即: ain,grain,in,n,rain
每个案例为一行字符串。
将子串排序输出
3.字符串匹配
字符串匹配问题:给出两个字符串,其中一个是文本串test(长度为\(n\)),另一个是模式串pattern(长度为\(m\)),如何判断模式串是否为文本串的一个子串?
暴力算法:将模式串和文本串逐字符比较,如果发生失配,那么就从字符串的下一个字符开始重新比较,知道完全匹配或遍历完整的文本串仍未成功。时间复杂度为\(o(mn)\)。
kmp算法:模式串失配后,并不是从下一个字符开始重新匹配,而是利用已有的信息,跳过一些不可能成功匹配的位置,以便尽量减少模式串与主串的匹配次数,进而达到快速匹配的目的。时间复杂度为\(o(m+n)\)。
预处理,求next数组:字符串的前缀与后缀相同的最大长度。
发生失配后,按照next数组进行跳转,之后重新尝试匹配。
given two sequences of numbers : a[1], a[2], ...... , a[n], and b[1], b[2], ...... , b[m] (1 <= m <= 10000, 1 <= n <= 1000000). your task is to find a number k which make a[k] = b[1], a[k + 1] = b[2], ...... , a[k + m - 1] = b[m]. if there are more than one k exist, output the smallest one.
the first line of input is a number t which indicate the number of cases. each case contains three lines. the first line is two numbers n and m (1 <= m <= 10000, 1 <= n <= 1000000). the second line contains n integers which indicate a[1], a[2], ...... , a[n]. the third line contains m integers which indicate b[1], b[2], ...... , b[m]. all integers are in the range of [-1000000, 1000000].
for each test case, you should output one line which only contain k described above. if no such k exists, output -1 instead.
给你两个数字序列,你的任务是再序列a中找到和序列b完全匹配的子串,如果有多个匹配的位置,输出最小的那个,如果没有输出-1。
the french author georges perec (1936–1982) once wrote a book, la disparition, without the letter 'e'. he was a member of the oulipo group. a quote from the book:
tout avait pair normal, mais tout s’affirmait faux. tout avait fair normal, d’abord, puis surgissait l’inhumain, l’affolant. il aurait voulu savoir où s’articulait l’association qui l’unissait au roman : stir son tapis, assaillant à tout instant son imagination, l’intuition d’un tabou, la vision d’un mal obscur, d’un quoi vacant, d’un non-dit : la vision, l’avision d’un oubli commandant tout, où s’abolissait la raison : tout avait l’air normal mais…
perec would probably have scored high (or rather, low) in the following contest. people are asked to write a perhaps even meaningful text on some subject with as few occurrences of a given “word” as possible. our task is to provide the jury with a program that counts these occurrences, in order to obtain a ranking of the competitors. these competitors often write very long texts with nonsense meaning; a sequence of 500,000 consecutive 't's is not unusual. and they never use spaces.
so we want to quickly find out how often a word, i.e., a given string, occurs in a text. more formally: given the alphabet {'a', 'b', 'c', …, 'z'} and two finite strings over that alphabet, a word w and a text t, count the number of occurrences of w in t. all the consecutive characters of w must exactly match consecutive characters of t. occurrences may overlap.
the first line of the input file contains a single number: the number of test cases to follow. each test case has the following format:
one line with the word w, a string over {'a', 'b', 'c', …, 'z'}, with 1 ≤ |w| ≤ 10,000 (here |w| denotes the length of the string w).
one line with the text t, a string over {'a', 'b', 'c', …, 'z'}, with |w| ≤ |t| ≤ 1,000,000.
for every test case in the input file, the output should contain a single number, on a single line: the number of occurrences of the word w in the text t.
给你一个文本串,再给你一个模式串,文本串中有多少个子串与模式串完全匹配。这道题其实和上道题非常相似,只不过上道题在遇到第一个匹配的地方后,会直接停止向后搜索,并输出位置。本题需要遍历完整文本串,并记录匹配成功的次数。
读入数据string[ ],然后读入一个短字符串。要求查找string[ ]中和短字符串的所有匹配,输出行号、匹配字符串。匹配时不区分大小写,并且可以有一个用中括号表示的模式匹配。如“aa[123]bb”,就是说aa1bb、aa2bb、aa3bb都算匹配。
输入有多组数据。
每组数据第一行输入n(1<=n<=1000),从第二行开始输入n个字符串(不含空格),接下来输入一个匹配字符串。
输出匹配到的字符串的行号和该字符串(匹配时不区分大小写)。
finding all occurrences of a pattern in a text is a problem that arises frequently in text-editing programs. typically,the text is a document being edited,and the pattern searched for is a particular word supplied by the user. we assume that the text is an array t[1..n] of length n and that the pattern is an array p[1..m] of length m<=n.we further assume that the elements of p and t are all alphabets(∑={a,b...,z}).the character arrays p and t are often called strings of characters. we say that pattern p occurs with shift s in the text t if 0<=s<=n and t[s+1..s+m] = p[1..m](that is if t[s+j]=p[j],for 1<=j<=m). if p occurs with shift s in t,then we call s a valid shift;otherwise,we calls a invalid shift. your task is to calculate the number of vald shifts for the given text t and p attern p.
for each case, there are two strings t and p on a line,separated by a single space.you may assume both the length of t and p will not exceed 10^6.
you should output a number on a separate line,which indicates the number of valid shifts for the given text t and pattern p.