英语字母的ASCII码为A-----Z:65------90;
而a-----------z为:97-----------122;
顺序递增
答案为 B;转换为十进制为:1*8*8+3*8+2=90 |||| (132) 8
/*由于不清楚C++字符串类的大小写转换的函数,只能将要比较的字符进行了转换*/
#include<iostream>
#include<string>
using namespace std;
int main(){
string input;
char target;
getline(cin, input);
cin >> target;
char target1;
if (target >= 65 && target <= 96)
target1 = target + 32;
if (target >= 97 && target <= 129)
target1 = target - 32;
int count = 0;
for (int i = 0; i<input.length(); ++i){
if (input[i] == target || input[i] == target1)
count++;
}
cout << count << endl;
return 0;
}
//优化 c++大小写转化
#include<iostream>
#include<string>
//#include<stdlib.h>
using namespace std;
int main()
{
string str;
char c;
getline(cin, str);
cin >> c;
int n = 0;
for (int i = 0; i<str.length(); i++)
{
if (tolower(c) == tolower(str[i]))
n++;
}
cout << n;
而a-----------z为:97-----------122;
顺序递增
答案为 B;转换为十进制为:1*8*8+3*8+2=90 |||| (132) 8
/*由于不清楚C++字符串类的大小写转换的函数,只能将要比较的字符进行了转换*/
#include<iostream>
#include<string>
using namespace std;
int main(){
string input;
char target;
getline(cin, input);
cin >> target;
char target1;
if (target >= 65 && target <= 96)
target1 = target + 32;
if (target >= 97 && target <= 129)
target1 = target - 32;
int count = 0;
for (int i = 0; i<input.length(); ++i){
if (input[i] == target || input[i] == target1)
count++;
}
cout << count << endl;
return 0;
}
//优化 c++大小写转化
#include<iostream>
#include<string>
//#include<stdlib.h>
using namespace std;
int main()
{
string str;
char c;
getline(cin, str);
cin >> c;
int n = 0;
for (int i = 0; i<str.length(); i++)
{
if (tolower(c) == tolower(str[i]))
n++;
}
cout << n;
}
http://zhidao.baidu.com/link?url=Xuw_e_sQ1MD4xPV4QoxK3lcV7JnM6knoqeIXUOK5NnOBwWHenZv12yopfq6Jb0C9DgTPT8r-ZM6poh5aH1WJt_
http://zhidao.baidu.com/link?url=_u5t4RkDT1sZy1MPOCW-JXDlHQu6rAl2UIFreUFEwwuYNO5ASBKTRcTjka3JLfRsDZqINQsNJHVVliWZAV_tuK
这个是华为老牛网的题