chapter 4 第二部分

课本习题4

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
	
	char a[100];
    int i,daxie,xiaoxie,space,number,other;
	cout<<"请输入字符长度小于100的文字:";
	cin.get(a,100);
	cout<<"the length of string is "<<strlen(a)<<endl;
	for(i=0;i<100;i++)
	{
		if (a[i]>='A'&&a[i]<='Z')
			daxie++;
		else if(a[i]>='a'&&a[i]<='z')
			xiaoxie++;
		else if(a[i]>='0'&&a[i]<='9')
			number++;
		else if(a[i]==' ')
			space++;
		else if (a[i]=='\0')
			other=strlen(a)-daxie-xiaoxie-number-space;
	}

		cout<<"其中大写字母的个数为:"<<daxie<<endl;
		cout <<"其中小写字母的个数为:"<<xiaoxie<<endl;
	    cout<<"其中数字的个数为:"<<number<<endl;
		cout<<"其他字符的个数为:"<<other<<endl;
		cout<<"空格的个数为:"<<space<<endl;
		return 0;
	}
习题五:

#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
	
	char str[100];
    cout<<"please input string:";
	cin.get(str,100);
	cout<<"字符串"<<str<<"的反向字符串为:\n";
	for(int i =strlen(str)-1;i>=0;i--)
		cout<<str[i];
		cout<<"the length of string"<<str<<"is"<<strlen(str)<<endl;
		return 0;
	}

	


#include <iostream>
#include <iomanip>
using namespace std;
int main ()
{
	
	char a[100],b[100];
	int i,j=0;
    cout<<"please input string:";
	cin.get(a,100);
	for(i=0;i<100;i++)
	{
		if(a[i]>='0'&&a[i]<='9')
			continue;
			b[j]=a[i];
		j++;
	}
	b[j]='\0';
	cout<<"删除数字后的字符串为:"<<b<<endl;
	cout<<"字符串的长度为:"<<j<<endl;
	return 0;
}








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值