问题 A: 字符串连接
时间限制: 1 Sec 内存限制: 32 MB
提交: 973 解决: 425
[提交][状态][讨论版][命题人:外部导入]
题目描述
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输入
每一行包括两个字符串,长度不超过100。
输出
可能有多组测试数据,对于每组数据,
不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。
输出连接后的字符串。
样例输入
abc def
样例输出
abcdef
#include <stdio.h>
#include <string.h>
#define max 220
int len(char s[])
{
int i=0,cnt=0;
while(s[i++]!='\0'){
cnt++;
}
return cnt;
}
int main()
{
char s1[max],s2[max];
while(scanf("%s %s",s1,s2)!=EOF){
int cnt1=0,cnt2=0,i=0;
cnt1=len(s1);
cnt2=len(s2);
int l=cnt1+cnt2;
for(i=0;i<cnt2;i++){
s1[cnt1++]=s2[i];
}
for(i=0;i<l;i++){
printf("%c",s1[i]);
}
printf("\n");
}
return 0;
}
问题 B: 首字母大写
时间限制: 1 Sec 内存限制: 32 MB
提交: 1457 解决: 410
[提交][状态][讨论版][命题人:外部导入]
题目描述
对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。
在字符串中,单词之间通过空白符分隔,空白符包括:空格(’ ‘)、制表符(’\t’)、回车符(’\r’)、换行符(’\n’)。
输入
输入一行:待处理的字符串(长度小于100)。
输出
可能有多组测试数据,对于每组数据,
输出一行:转换后的字符串。
样例输入
if so, you already have a google account. you can sign in on the right.
样例输出
If So, You Already Have A Google Account. You Can Sign In On The Right.
输入的时候只能用gets,因为scanf的%s是把空格和换行符作为结束符的;
思路很简单,把输入作为一个字符串用gets函数接收,然后判断第一个字符有没有大写,从第二个字符开始,每找到一个空白符,就判断空白符下一个符号是不是大写了
#include <stdio.h>
#include <string.h>
#define max 101
int main()
{
char str[max];
while(gets(str)!=NULL){
int i=0;
int len=strlen(str);
if(str[0]>='a'&&str[0]<='z') str[0]-=32;
for(i=1;i<len;i++){
if(str[i