#include #include using namespace std;

int t, cnt; char s[6];

// 判断数字 num 是否能匹配模板 s bool match(int num) { int len = strlen(s); char str[6]; // 将数字转化为字符串 sprintf(str, "%d", num); if (strlen(str) != len) return false; // 长度不匹配 for (int i = 0; i < len; i++) { if (s[i] == '?') continue; // 匹配任意数字 if (s[i] != str[i]) return false; // 数字不匹配 } return true; }

int main() { cin >> t; while (t--) { cin >> s; cnt = 0; for (int num = 1; num <= 100000; num++) { if (match(num)) cnt++; } cout << cnt << endl; } return 0; }

C++ 编程题:计算匹配整数模板的正整数个数

原文地址: https://www.cveoy.top/t/topic/oR6b 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录