oj--string

#include<cstdio>
#include<string>
int main(){
    string a="AAAA";
    string b="BBB";
    a.insert(2,b);
    cout<<a<<endl;
}

AABBBAA;在a中小标为2的字符前插入b字符串。string b也可以为字符数组。

时间: 2024-10-15 00:57:34

oj--string的相关文章

中南oj String and Arrays

题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?cid=2072&pid=1 Problem B: String and Arrays Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 222  Solved: 56[Submit][Status][Web Board] Description 有一个N*N的字符矩阵,从上到下依次记为第1行,第2行,……,第N行,从左至右依次记为第1列,第2列,……

LeetCode OJ String to Integer (atoi) 字符串转数字

1 #include <iostream> 2 #include <assert.h> 3 using namespace std; 4 int ato(const char *str) { 5 int i=0,e=0,s=0; 6 int max=2147483647,min=-2147483648; 7 int f=1; 8 int tem[10]={0}; 9 unsigned int pan=0; 10 while(*str==' '){ //过滤掉连续空格 11 str+

LeetCode OJ - Reverse Words in a String

题目: Given an input string, reverse the string word by word. For example, Given s = "the sky is blue", return "blue is sky the". 解题思路: 1.先对字符串进行一次总的翻转 2.以空格为单位,划分单词,然后对每个单词再进行一次翻转 代码: class Solution { public: void swap(char& a, char

&lt;LeetCode OJ&gt; 345. Reverse Vowels of a String

Total Accepted: 537 Total Submissions: 1488 Difficulty: Easy Write a function that takes a string as input and reverse only the vowels of a string. Example 1: Given s = "hello", return "holle". Example 2: Given s = "leetcode"

九度OJ 1094 String Matching

题目1094:String Matching 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1098 解决:587 题目描述: 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

Leet Code OJ 8. String to Integer (atoi) [Difficulty: Easy]

题目: Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be

九度OJ—题目1094:String Matching

题目描述: 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 th

bnu oj 34985 Elegant String (矩阵+dp)

Elegant String We define a kind of strings as elegant string: among all the substrings of an elegant string, none of them is a permutation of "0, 1,-, k". Let function(n, k) be the number of elegant strings of length n which only contains digits

Reverse Words in a String | LeetCode OJ | C++

我的思路:先读取每一个单词,存放到容器中:读取完毕后,将容器中的单词倒序写入输出中. #include<iostream> #include<string> #include<vector> using namespace std; void f(string &s){ vector<string> vs; string temp=""; int i=0; while(s[i]!='\0'){ //遍历直到结尾 if (s[i]=

Leet Code OJ 344. Reverse String [Difficulty: Easy]

题目: Write a function that takes a string as input and returns the string reversed. Example: Given s = "hello", return "olleh". 翻译: 写一个函数,使用字符串作为输入,返回它反转后的结果. 例如,输入"hello",返回"olleh". 分析: 转为字符数组后,将第一个字符和最后一个字符对调,第二个字符