題目描述:寫出一個程序,接收一個含有字母、數(shù)字以及空格組成的字符串,和一個字符,然后輸出輸入字符串中含有該字符的個數(shù)。不區(qū)分大小寫。
輸入描述:輸入一個含有字母和數(shù)字以及空格組成的字符串,和一個字符。
輸出描述:輸出輸入字符串中含有該字符的個數(shù)。
輸入例子:
ABCDEF
A
輸出例子:1
算法實現(xiàn):
#include <iostream>#include <string>using namespace std;/************************************************ * Author: 趙志乾 * Date: 2017-2-16 * Declaration: All Rigths Reserved !!! ***********************************************/ int main(){ string instr,inc; getline (cin,instr); getline (cin,inc); if(inc[0]>='a'&&inc[0]<='z') inc[0]=inc[0]-'a'+'A'; int count=0; for(int i=0;i<instr.length();i++) { if(instr[i]>='a'&&instr[i]<='z') instr[i]=instr[i]-'a'+'A'; if(instr[i]==inc[0]) count++; } cout<<count<<endl; return 0;}
新聞熱點
疑難解答
圖片精選