
字符串处理
小·幸·运
你的所有努力最后都会回赠予你。
展开
-
PAT乙级B1086 就不告诉你 (15 分)
做作业的时候,邻座的小盆友问你:“五乘以七等于多少?”你应该不失礼貌地围笑着告诉他:“五十三。”本题就要求你,对任何一对给定的正整数,倒着输出它们的乘积。输入格式:输入在第一行给出两个不超过 1000 的正整数 A 和 B,其间以空格分隔。输出格式:在一行中倒着输出 A 和 B 的乘积。输入样例:5 7输出样例:53思路:首先得出正确的结果ans,然...原创 2019-03-13 14:44:00 · 307 阅读 · 0 评论 -
PAT乙级B1040 有几个PAT (25 分)
字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T);第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T)。现给定字符串,问一共可以形成多少个 PAT?输入格式:输入只有一行,包含一个字符串,长度不超过105,只包含 P、A、T 三种字母。输出格式:在一行中输出给定字符串中包含多少个 ...原创 2019-02-07 22:02:43 · 131 阅读 · 0 评论 -
PAT甲级A1060 Are They Equal (25 分)
If a machine can save only 3 significant digits, the float numbers 12300 and 12358.9 are considered equal since they are both saved as 0.123×105 with simple chopping. Now given the number of signif...原创 2019-01-23 17:31:04 · 223 阅读 · 0 评论 -
PAT甲级A1071 Speech Patterns (25 分)
People often have a preference among synonyms of the same word. For example, some may prefer "the police", while others may prefer "the cops". Analyzing such patterns can help to narrow down a speaker...原创 2019-02-14 19:49:08 · 185 阅读 · 0 评论 -
PAT乙级B1033 旧键盘打字 (20 分)
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及坏掉的那些键,打出的结果文字会是怎样?输入格式:输入在 2 行中分别给出坏掉的那些键、以及应该输入的文字。其中对应英文字母的坏键以大写给出;每段文字是不超过 105 个字符的串。可用的字符包括字母 [a-z, A-Z]、数字 0-9、以及下划线 _(代表空格)、,、.、-、+(代表上档键...原创 2019-01-28 20:48:33 · 384 阅读 · 1 评论 -
PAT乙级B1029 旧键盘 (20 分)
旧键盘上坏了几个键,于是在敲一段文字的时候,对应的字符就不会出现。现在给出应该输入的一段文字、以及实际被输入的文字,请你列出肯定坏掉的那些键。输入格式:输入在 2 行中分别给出应该输入的文字、以及实际被输入的文字。每段文字是不超过 80 个字符的串,由字母 A-Z(包括大、小写)、数字 0-9、以及下划线 _(代表空格)组成。题目保证 2 个字符串均非空。输出格式:按照发现顺序,在...原创 2019-01-27 17:06:39 · 159 阅读 · 0 评论 -
PAT甲级A1040 Longest Symmetric String(25 分)
Given a string, you are supposed to output the length of the longest symmetric sub-string. For example, given Is PAT&TAP symmetric?, the longest symmetric sub-string is s PAT&TAP s, hence you ...原创 2018-08-30 21:28:51 · 212 阅读 · 0 评论 -
PAT甲级A1031 Hello World for U (20)
Given any string of N (>=5) characters, you are asked to form the characters into the shape of U. For example, "helloworld" can be printed as:h de ll rlowoThat is, the characters must be...原创 2018-08-18 21:54:53 · 166 阅读 · 0 评论 -
PAT甲级A1024 Palindromic Number (25)
A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers...原创 2018-08-14 21:17:49 · 162 阅读 · 0 评论 -
C++中string与*char,char[]的几种转换方式
C++中string、char *、char[]的转换 头段时间有人问过我这个问题,可是我一点头绪都没有,直接说不会。现在从网上找了点资料,看了看,知道点东西了。 一、string转char*。 主要有三种方法可以将str转换为char*类型,分别是:data(); c_str(); copy(); 1.data()方法,如:1 string str = "hello...转载 2018-07-30 21:23:14 · 275 阅读 · 0 评论 -
PAT甲级A1010 Radix (25)
Given a pair of positive integers, for example, 6 and 110, can this equation 6 = 110 be true? The answer is "yes", if 6 is a decimal number and 110 is a binary number.Now for any pair of positive in...原创 2018-07-26 21:19:55 · 305 阅读 · 0 评论 -
PAT甲级A1005 Spell It Right (20)
Given a non-negative integer N, your task is to compute the sum of all the digits of N, and output every digit of the sum in English.Input Specification:Each input file contains one test case. Eac...原创 2018-07-19 21:56:30 · 158 阅读 · 0 评论 -
LeetCode--606. Construct String from Binary Tree
You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair "()". And you ne...原创 2018-07-07 22:51:24 · 117 阅读 · 0 评论 -
LeetCode--551. Student Attendance Record I
You are given a string representing an attendance record for a student. The record only contains the following three characters:'A' : Absent. 'L' : Late. 'P' : Present. A student could be rewarded if ...原创 2018-07-07 20:16:26 · 201 阅读 · 0 评论 -
LeetCode--557. Reverse Words in a String III
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"Outpu...原创 2018-07-07 19:44:14 · 164 阅读 · 0 评论 -
LeetCode--859. Buddy Strings
Given two strings A and B of lowercase letters, return true if and only if we can swap two letters in A so that the result equals B. Example 1:Input: A = "ab", B = "ba"Output: trueExample 2:Input: A...原创 2018-07-11 22:26:28 · 349 阅读 · 0 评论 -
PAT乙级B1044 火星数字 (20 分)
火星人是以 13 进制计数的:地球人的 0 被火星人称为 tret。 地球人数字 1 到 12 的火星文分别为:jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec。 火星人将进位以后的 12 个高位数字分别称为:tam, hel, maa, huh, tou, kes, hei, elo, syy, lok, mer, jo...原创 2019-02-08 14:59:41 · 230 阅读 · 0 评论 -
PAT乙级B1048 数字加密 (20 分)
本题要求实现一种数字加密方法。首先固定一个加密用正整数 A,对任一正整数 B,将其每 1 位数字与 A 的对应位置上的数字进行以下运算:对奇数位,对应位的数字相加后对 13 取余——这里用 J 代表 10、Q 代表 11、K 代表 12;对偶数位,用 B 的数字减去 A 的数字,若结果为负数,则再加 10。这里令个位为第 1 位。输入格式:输入在一行中依次给出 A 和 B,均为不超过 10...原创 2019-02-08 21:18:03 · 160 阅读 · 0 评论 -
PAT甲级A1069 The Black Hole of Numbers (20 分)
For any 4-digit integer except the ones with all the digits being the same, if we sort the digits in non-increasing order first, and then in non-decreasing order, a new number can be obtained by takin...原创 2019-02-10 21:06:40 · 254 阅读 · 0 评论 -
PAT甲级A1140 Look-and-say Sequence (20 分)
Look-and-say sequence is a sequence of integers as the following:D, D1, D111, D113, D11231, D112213111, ...where D is in [0, 9] except 1. The (n+1)st number is a kind of description of the nth n...原创 2019-03-12 16:47:53 · 261 阅读 · 0 评论 -
PAT乙级B1084 外观数列 (20 分)
外观数列是指具有以下特点的整数序列:d, d1, d111, d113, d11231, d112213111, ...它从不等于 1 的数字 d 开始,序列的第 n+1 项是对第 n 项的描述。比如第 2 项表示第 1 项有 1 个 d,所以就是 d1;第 2 项是 1 个 d(对应 d1)和 1 个 1(对应 11),所以第 3 项就是 d111。又比如第 4 项是 d113,其描...原创 2019-03-12 15:15:18 · 297 阅读 · 0 评论 -
PAT乙级B1093 字符串A+B (20 分)
给定两个字符串 A 和 B,本题要求你输出 A+B,即两个字符串的并集。要求先输出 A,再输出 B,但重复的字符必须被剔除。输入格式:输入在两行中分别给出 A 和 B,均为长度不超过 106的、由可见 ASCII 字符 (即码值为32~126)和空格组成的、由回车标识结束的非空字符串。输出格式:在一行中输出题面要求的 A 和 B 的和。输入样例:This is a ...原创 2019-03-16 13:40:16 · 173 阅读 · 0 评论 -
PAT乙级B1079 延迟的回文数 (20 分)
给定一个 k+1 位的正整数 N,写成 ak⋯a1a0 的形式,其中对所有 i 有 0≤ai<10 且 ak>0。N 被称为一个回文数,当且仅当对所有 i 有 ai=ak−i。零也被定义为一个回文数。非回文数也可以通过一系列操作变出回文数。首先将该数字逆转,再将逆转数与该数相加,如果和还不是一个回文数,就重复这个逆转再相加的操作,直到一个回...原创 2019-03-11 19:36:42 · 195 阅读 · 0 评论 -
PAT甲级A1136 A Delayed Palindrome (20 分)
Consider a positive integer N written in standard notation with k+1 digits ai as ak⋯a1a0 with 0≤ai<10 for all i and ak>0. Then N is palindromic if and only if ai=ak−i for...原创 2019-03-11 19:32:21 · 206 阅读 · 0 评论 -
PAT甲级A1152 Google Recruitment (20 分)
In July 2004, Google posted on a giant billboard along Highway 101 in Silicon Valley (shown in the picture below) for recruitment. The content is super-simple, a URL consisting of the first 10-digit p...原创 2019-03-15 16:47:59 · 273 阅读 · 0 评论 -
PAT乙级B1078 字符串压缩与解压 (20 分)
文本压缩有很多种方法,这里我们只考虑最简单的一种:把由相同字符组成的一个连续的片段用这个字符和片段中含有这个字符的个数来表示。例如 ccccc 就用 5c 来表示。如果字符没有重复,就原样输出。例如 aba 压缩后仍然是 aba。解压方法就是反过来,把形如 5c 这样的表示恢复为 ccccc。本题需要你根据压缩或解压的要求,对给定字符串进行处理。这里我们简单地假设原始字符串是完全由英文字母...原创 2019-03-07 20:00:38 · 222 阅读 · 0 评论 -
PAT乙级B1074 宇宙无敌加法器 (20 分)
地球人习惯使用十进制数,并且默认一个数字的每一位都是十进制的。而在 PAT 星人开挂的世界里,每个数字的每一位都是不同进制的,这种神奇的数字称为“PAT数”。每个 PAT 星人都必须熟记各位数字的进制表,例如“……0527”就表示最低位是 7 进制数、第 2 位是 2 进制数、第 3 位是 5 进制数、第 4 位是 10 进制数,等等。每一位的进制 d 或者是 0(表示十进制)、或者是 [2,9]...原创 2019-03-07 14:22:57 · 246 阅读 · 0 评论 -
PAT甲级A1084 Broken Keyboard (20 分)
On a broken keyboard, some of the keys are worn out. So when you type some sentences, the characters corresponding to those keys will not appear on screen.Now given a string that you are supposed to...原创 2019-02-20 20:53:30 · 121 阅读 · 0 评论 -
PAT甲级A1082 Read Number in Chinese (25 分)
Given an integer with no more than 9 digits, you are supposed to read it in the traditional Chinese way. Output Fu first if it is negative. For example, -123456789 is read as Fu yi Yi er Qian san Bai ...原创 2019-02-20 17:41:39 · 365 阅读 · 2 评论 -
PAT甲级A1100 Mars Numbers (20 分)
People on Mars count their numbers with base 13:Zero on Earth is called "tret" on Mars. The numbers 1 to 12 on Earth is called "jan, feb, mar, apr, may, jun, jly, aug, sep, oct, nov, dec" on Mars, ...原创 2019-02-25 16:30:28 · 154 阅读 · 0 评论 -
PAT甲级A1112 Stucked Keyboard (20 分)
On a broken keyboard, some of the keys are always stucked. So when you type some sentences, the characters corresponding to those keys will appear repeatedly on screen for k times.Now given a result...原创 2019-02-28 19:00:21 · 204 阅读 · 0 评论 -
PAT甲级A1108 Finding Average (20 分)
The basic task is simple: given N real numbers, you are supposed to calculate their average. But what makes it complicated is that some of the input numbers might not be legal. A legal input is a real...原创 2019-02-27 15:20:27 · 214 阅读 · 0 评论 -
PAT甲级A1077 Kuchiguse (20 分)
The Japanese language is notorious for its sentence ending particles. Personal preference of such particles can be considered as a reflection of the speaker's personality. Such a preference is called ...原创 2019-02-17 17:33:23 · 314 阅读 · 0 评论 -
LeetCode--929. Unique Email Addresses
Every email consists of a local name and a domain name, separated by the @ sign.For example, in alice@leetcode.com, alice is the local name, and leetcode.com is the domain name.Besides lowercase l...原创 2019-02-11 16:10:18 · 375 阅读 · 0 评论 -
LeetCode--824. Goat Latin
A sentence S is given, composed of words separated by spaces. Each word consists of lowercase and uppercase letters only.We would like to convert the sentence to "Goat Latin" (a made-up language simil...原创 2018-07-11 21:54:06 · 330 阅读 · 0 评论 -
LeetCode--819. Most Common Word
Given a paragraph and a list of banned words, return the most frequent word that is not in the list of banned words. It is guaranteed there is at least one word that isn't banned, and that the answer...原创 2018-07-11 21:27:02 · 202 阅读 · 0 评论 -
LeetCode--14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["flower","flow","flight"]Output: "fl"E...原创 2018-06-12 21:39:16 · 114 阅读 · 0 评论 -
LeetCode--13. Roman to Integer
Roman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 5...原创 2018-06-12 21:23:30 · 137 阅读 · 0 评论 -
LeetCode-804-Unique Morse Code Words
International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ".-", "b" maps to "-...", "c" maps to "-.-.", and so on.F原创 2018-05-24 17:21:07 · 146 阅读 · 0 评论 -
LeetCode--20. Valid Parentheses
Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets must be closed by the same type of b...原创 2018-06-11 21:43:28 · 126 阅读 · 0 评论