如何实现字符串处理的C语言编程?

更新于
2026-10-10 09:21:44
1阅读来源:SEO教程
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计570个文字,预计阅读时间需要3分钟。

如何实现字符串处理的C语言编程?

编写一个程序,实现以下功能:接收两个字符串,不使用任何字符串库函数,将它们无序地连接起来。输入每行包含两个字符串,长度不超过100。输出可能有多组测试数据。

1、字符串连接

题目描述 不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。

如何实现字符串处理的C语言编程?

输入 每一行包括两个字符串,长度不超过100。

输出 可能有多组测试数据,对于每组数据, 不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。 输出连接后的字符串。

#include<iostream> using namespace std; #include<cstring> int main() { char s1[105],s2[105]; while(scanf("%s%s",s1,s2)!=EOF) { int len1=strlen(s1); int len2=strlen(s2); char s[len1+len2+2]; int k=0; for(int i=0;i<len1;i++) { s[k++]=s1[i]; } for(int i=0;i<len2;i++) { s[k++]=s2[i]; } s[k]='\0'; printf("%s\n",s); } return 0; }

2、字符串首字母大写

题目描述 对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。 在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\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.

#include<iostream> using namespace std; #include<cstring> #include<cctype> int main() { string s; while(getline(cin,s)) { s[0]=toupper(s[0]);//要重新赋值 for(unsigned i=1;i<s.length();i++) { char c=s[i-1]; if(c==' '||c=='\t'||c=='\n'||c=='\r') { s[i]=toupper(s[i]); } } cout<<s<<endl; } return 0; }

本文共计570个文字,预计阅读时间需要3分钟。

如何实现字符串处理的C语言编程?

编写一个程序,实现以下功能:接收两个字符串,不使用任何字符串库函数,将它们无序地连接起来。输入每行包含两个字符串,长度不超过100。输出可能有多组测试数据。

1、字符串连接

题目描述 不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。

如何实现字符串处理的C语言编程?

输入 每一行包括两个字符串,长度不超过100。

输出 可能有多组测试数据,对于每组数据, 不借用任何字符串库函数实现无冗余地接受两个字符串,然后把它们无冗余的连接起来。 输出连接后的字符串。

#include<iostream> using namespace std; #include<cstring> int main() { char s1[105],s2[105]; while(scanf("%s%s",s1,s2)!=EOF) { int len1=strlen(s1); int len2=strlen(s2); char s[len1+len2+2]; int k=0; for(int i=0;i<len1;i++) { s[k++]=s1[i]; } for(int i=0;i<len2;i++) { s[k++]=s2[i]; } s[k]='\0'; printf("%s\n",s); } return 0; }

2、字符串首字母大写

题目描述 对一个字符串中的所有单词,如果单词的首字母不是大写字母,则把单词的首字母变成大写字母。 在字符串中,单词之间通过空白符分隔,空白符包括:空格(' ')、制表符('\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.

#include<iostream> using namespace std; #include<cstring> #include<cctype> int main() { string s; while(getline(cin,s)) { s[0]=toupper(s[0]);//要重新赋值 for(unsigned i=1;i<s.length();i++) { char c=s[i-1]; if(c==' '||c=='\t'||c=='\n'||c=='\r') { s[i]=toupper(s[i]); } } cout<<s<<endl; } return 0; }