描述 编写一个程序实现将字符串中的所有"you"替换成"we" 输入 输入包含多行数据 每行数据是一个字符串,长度不超过1000 数据以EOF结束 输出 对于输入的每一行,输出替换后的字符串 样例输入 you are what you do 样例输出 we are what we do STL string 练手题: 熟悉 find 函数,以及 replace 函数 //Asimple #include <iostream> #include <s…
For each list of words, output a line with each word reversed without changing the order of the words. This problem contains multiple test cases! The first line of a multiple input is an integer N, then a blank line followed by N input blocks. Each i…
2014-03-18 02:12 题目:判断一个字符串是否由另一个字符串循环移位而成. 解法:首先长度必须相等.然后将第一个串连拼两次,判断第二个串是否在这个连接串中. 代码: // 1.8 Assume you have a method isSubstring which checks if one word is a substring of another. Given two strings, s1 and s2, write code to check if s2 is a rota…
2014-03-18 01:36 题目:给定一个字符串,将其中的空格‘ ’替换为‘%20’,你可以认为字符串尾部有足够空间来容纳新增字符.请不要额外开辟数组完成. 解法:先从前往后统计空格个数,然后从后往前填充字符,以免其他无关字符被‘%20’覆盖掉. 代码: // 1.4 Write a method to replace all spaces in a string with '%20'. // do it in-place and backward. #include <cstdio>…
2014-03-18 01:25 题目:给定一个字符串,判断其中是否有重复字母. 解法:对于可能有n种字符的字符集,用一个长度为n的数组统计每个字符的出现次数,大于1则表示有重复. 代码: // 1.1 Implement an algorithm to determine if a string has all unique characters. What if you cannot use additional data structure? #include <cstdio> #inc…
Surprising Strings Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6193 Accepted: 4036 Description The D-pairs of a string of letters are the ordered pairs of letters that are distance D from each other. A string is D-unique if all of…
题目链接 ZOJ Monthly, March 2018 Problem G 题意 给定一个字符串.现在求一个下标范围$[0, n - 1]$的$01$序列$f$.$f[x] = 1$表示存在一种方案,删掉原字符串中的连续$x$个字母, 使得剩下的字符串中任意相邻的两个字母都不同.在这道题中所有的字符串首尾字符看做是相邻的. 对于每个起始位置求出最多往右延伸到的位置,满足该区间代表的字符串是一个满足任意相邻字母不同的字符串. 首先考虑一个连续的满足任意相邻字母不同的字符串.设其长度为$l$…