用string数组来存每一位的数字
遍历数组,如果是数字为[0][6][9],则cnt+=1;
如果是[8]cnt+=2;
最后输出cnt;
需要注意的是,定义变量后记得初始化cnt=0哦!
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl "\n"
#define PII pair<int,int>
#define PIII pair<int,PII>
const int MOD = 1e9 + 7;
const int N = 3e5;
bool cmp(PII p1, PII p2) {
return p1.first + p1.second < p2.first + p2.second;
}
void slu() {
string t;
cin >> t;
int cnt = 0;
for (int i = 0; i < t.size(); i++) {
if (t[i] == '8')cnt += 2;
else if (t[i] == '0' || t[i] == '6' || t[i] == '9')cnt++;
}
cout << cnt;
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int T;
// cin >> T;
T = 1;
while (T--)slu();
}

京公网安备 11010502036488号