- 十六周项目二
- 复制字符串str1,保存到str2中;
- 在字符串str2后面增加符号"//comment:"
- 将str1和str2接起来存放到str3中;
- 将str1中的空格去除,仍保存在str1中;
- 将str1和str2接起来,仍存放在str1中;
- 去除str1中的多余空格(即两个单词中间仅保留一个空格)。
- 在字符串前加5个符号"note:"
- 选择:将str1和st如连接 放在str3中
* /
* Copyright (c) 2011, 烟台大学计算机学院
* All rights reserved.
* 作 者: 孙培培
* 完成日期:2012 年 12月13 日
* 版 本 号:v1.0
* 输入描述:
* 问题描述:
* 程序输出:
* 问题分析:
#include <iostream>
using namespace std;
int main()
{
char str1[50]="I tell you that I will be strongwilled.",str2[50]="I believe that you will.",str3[100];
int i=0,j=0,k=0;
cout<<"原字符串[1]:I tell you that I will be strongwilled."<<endl;
cout<<"原字符串[2]:I believe that you will."<<endl;
for(i=0;str1[i]!='\0';i++)
{
if(str1[i]!=' ')
{
str3[k]=str1[i];
k++;
}
}
str3[k]='\0';
for(j=0;str2[j]!='\0';j++)
{
if(str2[j]!=' ')
{
str3[k]=str2[j];
k++;
}
}
str3[k]='\0'; //切记
cout<<"整理后的字符串为:"<<endl<<str3<<endl;
return 0;
}
项目二扩展----数组加法
最新推荐文章于 2024-02-12 12:19:48 发布