欢迎来到天天文库
浏览记录
ID:34523211
大小:56.85 KB
页数:6页
时间:2019-03-07
《数据结构与算法分析 第5章 larry nyhoff 清华大学出版社new》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Chapter5Chapter5:StandardC++Input/OutputandStringClassesExercises5.21.intstringCount(conststring&str,conststring&target)/*-------------------------------------------------------------------Findthenumberoftimesstringstrappearsinstringtarget.-----------------------------------------------------
2、--------------*/{intmatches=0;intposition=target.find(str);while(position!=string::npos){matches++;position=target.find(str,position+1);}returnmatches;}2.stringmonthName(intmonthNumber)/*-------------------------------------------------Convertamonthnumbertoitscorrespondingname.---------------
3、------------------------------------*/{switch(monthNumber){case(1):return"January";case(2):return"February";case(3):return"March";case(4):return"April";case(5):return"May";case(6):return"June";case(7):return"July";case(8):return"August";case(9):return"September";case(10):return"October";case(
4、11):return"November";case(12):return"December";default:cout<<"Month:illegalmonthnumber:"<//isupper(),tolower()intmonthNumber(stringmonthName)/*--------------------------------------------------Convertamonthnametoitscorrespondingnumber.--------
5、--------------------------------------------*/{for(inti=0;i6、="may")return5;if(monthName=="june")return6;if(monthName=="july")return7;if(monthName=="august")return8;if(monthName=="september")return9;if(monthName=="october")return10;if(monthName=="november")return11;if(monthName=="december")return12;cout<<"MonthNumber:illegalmonthname:"<7、dl;return0;}4.#include//islower(),toupper(),isupper(),tolower()stringlowerToUpper(stringstr)/*--------------------------------------------------Finduppercaseequivalentofastringstr.----------------------------------------------------*/
6、="may")return5;if(monthName=="june")return6;if(monthName=="july")return7;if(monthName=="august")return8;if(monthName=="september")return9;if(monthName=="october")return10;if(monthName=="november")return11;if(monthName=="december")return12;cout<<"MonthNumber:illegalmonthname:"<7、dl;return0;}4.#include//islower(),toupper(),isupper(),tolower()stringlowerToUpper(stringstr)/*--------------------------------------------------Finduppercaseequivalentofastringstr.----------------------------------------------------*/
7、dl;return0;}4.#include//islower(),toupper(),isupper(),tolower()stringlowerToUpper(stringstr)/*--------------------------------------------------Finduppercaseequivalentofastringstr.----------------------------------------------------*/
此文档下载收益归作者所有