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 ...
随机推荐
- Fiddler 域名过滤
原来一直没意识到Fiddler过滤,导致每次抓包都要自己判断.搜索好多东西,真是呵呵! 过滤设置很简单,看懂一张图就解决问题了. 箭头 那两处设置下,圆圈处保存再进行抓包即可
- 仿制的ActivityIndicatorView
仿制Github上CSS3效果制作的几个简单的ActivityIndicator,复习一下IOS动画操作. 原效果连接:https://github.com/tobiasahlin/SpinKit 代 ...
- Oracle EBS-SQL (QA-2):检查接收未检验.SQL
SELECT rsh.receipt_num 收据号, pov.vendor ...
- Java webservice
webservice: 就是应用程序之间跨语言的调用 1.xml 2. wsdl: webservice description language web服务描述语言 ...
- hdu1258Sum It Up (DFS)
Description Given a specified total t and a list of n integers, find all distinct sums using numbers ...
- #include <set>
1 multiset 多重集合(multiset) 允许存在两个次序相等的元素的集合 <set> 2 set 集合(set) 由节点组成的红黑树,每个节点都包含着一个元素,节点之间以某种作 ...
- 【JSON异常系列】new JSONObject对象时卡死原因
8:47 2015/7/11 昨天晚上在使用JSON时,在创建JSONObject对象的时候不报错也不抛出异常.但就是new 不出来JSONObject的对象,这是一个非常奇葩的现象. 最后才发现原来 ...
- Devexpress之barManager控件属性
隐藏菜单栏左边的竖线和右边的箭头? 1.隐藏菜单栏上右边的箭头属性设置:OptionsBar=>>AllowQuickCustomization=False 2.隐藏菜单栏左边的竖线属性设 ...
- Java基础笔记-多线程
线程: 方式一:继承Thread类并且复写run方法. 格式: class MyThread extends Thread { public void run() { 线程中要运行的代码. } } 其 ...
- C#核编之系统数据类型和相应的C#关键字
和任何编程语言一样,C#定义了一组用于表示局部变量.成员变量.返回值以及输入参数的基本数据类型.然而,与其他编程语言不同的是,这些关键字不只是编译器能识别的标记.C#关键字其实是System命名空间中 ...