chapter 4 第二部分
2014-04-22 23:46
246 查看
课本习题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; }
相关文章推荐
- Scala Cookbook翻译 Chapter 2.Numbers 第二部分
- Scala Cookbook读书笔记 Chapter 3.Control Structures 第二部分
- 《C++捷径教程》读书笔记--Chapter 11--类(第二部分)
- 犀牛书第五版读书笔记——Chapter 14. Scripting Browser Windows(第二部分)
- chapter 3(第二部分)
- 《C++捷径教程》读书笔记--Chapter 5--数组和字符串(第二部分)
- Scala Cookbook翻译 Chapter 1.Strings 第二部分
- 犀牛书第五版读书笔记——Chapter 15. Scripting Documents(第二部分)
- 《C++捷径教程》读书笔记--Chapter 6--指针(第二部分)
- 《C++捷径教程》读书笔记--Chapter 7--函数,第一部分:基础知识(第二部分)
- 《C++捷径教程》读书笔记--Chapter 8--函数,第二部分:引用,重载和默认参数
- Scala Cookbook读书笔记 Chapter 4.Classes and Properties 第二部分
- 犀牛书第五版读书笔记——Chapter 9. Classes, Constructors, and Prototypes(第二部分)
- 《C++捷径教程》读书笔记--Chapter 9--更多的数据类型与运算符(第二部分)
- WPF Unleashed Chapter 2:XAML Demystified 翻译(第二部分)
- 犀牛书第五版读书笔记——Chapter 13. JavaScript in Web Browsers(第二部分)
- 《C++捷径教程》读书笔记--Chapter 4--程序控制语句(第二部分)
- servlet&jsp高级:第二部分
- 使用百度云主机的GPU主机教程_第二部分
- 理解JPA,第二部分:JPA中的关系