第一部分 C++语言
第五章 数组
第三节 字符类型和字符数组
1129 统计数字字符个数
#include <iostream>
using namespace std;
int main() {
char ch;
int cnt = 0;
while (cin >> ch) {
if (ch >= '0' && ch <= '9') cnt ++;
}
cout << cnt << endl;
return 0;
}
1130 找第一个只出现一次的字符
#include <iostream>
using namespace std;
int main() {
string s;
int a[26] = {};
cin >> s;
for (int i = 0; i < s.size(); i ++ ) {
a[s[i]-'a'] ++;
}
for (int i = 0; i < s.size(); i ++ ) {
if (a[s[i]-'a'] == 1) {
cout << s[i] << endl;
return 0;
}
}
cout << "no" << endl;
return 0;
}
1131 基因相关性
#include <iostream>
using namespace std;
int main() {
double x;
string a, b;
int cnt = 0;
cin >> x >> a >> b;
for (int i = 0; i < a.size(); i ++ ) {
if (a[i] == b[i]) cnt ++;
}
if (1.0*cnt/a.size() >= x) cout << "yes" << endl;
else cout << "no" << endl;
return 0;
}
1132 石头剪刀布
#include <iostream>
using namespace std;
int main() {
int n;
string p1,p2;
cin >> n;
while (n--) {
cin >> p1 >> p2;
if (p1 == p2) cout << "Tie" << endl;
if (p1 == "Rock" && p2 == "Scissors") cout << "Player1" << endl;
if (p1 == "Rock" && p2 == "Paper") cout << "Player2" << endl;
if (p1 == "Scissors" && p2 == "Rock") cout << "Player2" << endl;
if (p1 == "Scissors" && p2 == "Paper") cout << "Player1" << endl;
if (p1 == "Paper" && p2 =