POJ——字符串插入
欢迎来我的个人网站:http://www.rxwcv.cn
2:字符串插入
- 总时间限制:
- 1000ms
- 内存限制:
- 65536kB
- 描述
- 有两个字符串str和substr,str的字符个数不超过10,substr的字符个数为3。(字符个数不包括字符串结尾处的'\0'。)将substr插入到str中ASCII码最大的那个字符后面,若有多个最大则只考虑第一个。
- 输入
- 输入包括若干行,每一行为一组测试数据,格式为
str substr - 输出
- 对于每一组测试数据,输出插入之后的字符串。
- 样例输入
-
abcab eee
12343 555 - 样例输出
-
abceeeab
12345553# include<stdio.h>
# include<string.h> int main(void)
{
char s1[], s2[];
int i;
while(scanf("%s%s", s1, s2)!=EOF)
{
int max=;
int len=strlen(s1);
for(i=; i<len; i++)
{
if(s1[i]>s1[max])
{
max=i;
}
}
for(i=; i<=max; i++)
printf("%c", s1[i]);
printf("%s", s2);
for(i=max+; i<len; i++)
printf("%c", s1[i]);
printf("\n");
} return ;
}或
#include <cstdio>
#include <cstring> const int MAX_STRING_LEN = ; bool readLine(char *str, char *substr)
{
bool bEof = false; if ( == fscanf(stdin, "%s %s", str, substr))
{
bEof = true;
} return bEof;
} void insert(char *str, char *substr)
{
int i, maxIdx;
size_t size = strlen(str); // find the index of the maximum ascii code
maxIdx = ;
for (i=; i<size; ++i)
{
if (str[maxIdx] < str[i])
{
maxIdx = i;
}
} // shift right to make space
for (i=size; i>maxIdx; --i)
{
str[i+] = str[i];
} // insert the substr
++i;
str[i++] = substr[];
str[i++] = substr[];
str[i] = substr[];
} void print(char *str)
{
printf("%s\n", str);
} int main(void)
{
char str[MAX_STRING_LEN] = {'\0'};
char substr[MAX_STRING_LEN] = {'\0'}; while (readLine(str, substr))
{
insert(str, substr);
print(str);
} return ;
}欢迎来我的个人网站:http://www.rxwcv.cn
POJ——字符串插入的更多相关文章
- sql字符串插入函数STUFF
STUFF (Transact-SQL) SQL Server 2012 其他版本 此主题尚未评级 - 评价此主题 <?XML:NAMESPACE PREFIX = "[default ...
- JavaScript字符串插入、删除、替换函数
JavaScript字符串插入.删除.替换函数 说明: 以下函数中前两个函数取出查找字符串的前一部分和后一部分,以用于其他函数.注意,调用一次 replaceString(mainStr,search ...
- C#给字符串赋予字面值——字符串插入、转义序列的使用
1.占位符.字符串插入 给字符串赋予字面值时,经常遇见在字符串中包含变量的情况,用连接符进行拼接.转换的方式比较麻烦.还容易出错.C#提供了较为便捷的处理方式,即‘占位符’,以及C#6的新功能‘插入字 ...
- [c/c++] programming之路(24)、字符串(五)——字符串插入,字符串转整数,删除字符,密码验证,注意事项
1.将字符串插入到某位置(原字符串“hello yincheng hello cpp hello linux”,查找cpp,找到后在cpp的后面插入字符串“hello c”) 需要用到strstr字符 ...
- 笔记:iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)(别人的代码直接复制过来的,我脸皮有点厚)
NSString* str=@"hello";//存在代码区,不可变 NSLog(@"%@",str); //1.[字符串插入] NSMutableString ...
- iOS字符串的各种用法(字符串插入、字符串覆盖、字符串截取、分割字符串)
NSString* str=@"hello";//存在代码区,不可变 NSLog(@"%@",str); //1.[字符串插入] NSMutableString ...
- [转] POJ字符串分类
POJ 1002 - 487-3279(基础)http://acm.pku.edu.cn/JudgeOnline/problem?id=1002题意:略解法:二叉查找数,map,快排... POJ 1 ...
- SQL Server ->> SET ANSI_PADDING对于字符串插入的影响
前面写了<SQL Server ->> 字符串对比>讲了SQL Server在做字符串对比和排序时的对尾随空格的处理方法. 再说说有一个和字符串尾随空格相关联的东西就是SET ...
- (转载)将一段符合XML格式规范字符串插入已有XML文档当中
想我们已经存在一个XML文档,结构如下: < xmlversion="1.0"encoding="utf-8">< employees&g ...
随机推荐
- 补丁惹的祸-ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService
未找到与约束ContractName Microsoft.VisualStudio.Text.ITextDocumentFactoryService...匹配的导出 问题: 重新安装了VS2012,结 ...
- eclipse 软件的背景颜色、字体设置
1.eclipse 背景色设置: Window->Preferences->General->Editors->Text Editors->Backgroud color ...
- 几个常用道的macro
几个常用道的macro1.macro(1)#error msg 指令使編譯器停止執行並打印一條語句,(2)printf("%d,%s",_LINE_,_FILE_)打印當前行號和文 ...
- 为什么不能在scrollview中直接添加一个image,然后使animation.begin()??
http://stackoverflow.com/questions/17267451/animation-cant-begin-in-scrollview-in-windows-phone 以上是我 ...
- html5实现烟花绽放效果
来源地址:http://codepen.io/whqet/pen/Auzch 1.HTML5 你懂的,先看效果: 2.Html代码 <!-- setup our canvas element - ...
- MindManager_9.1.157使用模板时显示“参数错误”
每次使用标准模板时都出现这个问题,上网搜索,原来是模板中存在的 “注释”导致的问题.具体原因不详,解决起来也简单,就是繁琐一点.转抄如下: 先找到模板文件夹,共四个文件夹Communcation.Pe ...
- IKAnalyzer使用停用词词典进行分词
@Test // 測试分词的效果,以及停用词典是否起作用 public void test() throws IOException { String text = "老爹我们都爱您.&qu ...
- 运用Autoconf和Automake生成Makefile的学习之路
作为Linux下的程序开发人员,大家一定都遇到过Makefile,用make命令来编译自己写的程序确实是很方便.一般情况下,大家都是手工写一个简单Makefile,如果要想写出一个符合自由软件惯例的M ...
- Java反射及依赖注入简单模拟
一.编写Dao类 ? 1 2 3 4 5 6 7 8 9 10 11 package cn.com.songjy.annotation; import java.util.Date; publ ...
- 【字母树+贪心】【HDU3460】【Ancient Printer】
题目大意: 一个打印机 只有 打印,删除,a-z.操作 给你一堆队名,如何才能操作次数最少输出全部 (字典树节点数-1)*2 输入,删除操作数 字符串数 printf操作数 最长字符串的长度 最后一个 ...