Run ID:1833

提交时间:2023-11-12 00:03:50

#include <iostream> int main() { int countA = 0, countB = 0, totalCount = 1000, matchCount = 0; int numberA = 1, numberB = 1; while (countA < totalCount && countB < totalCount) { if (numberA == numberB) { matchCount++; } // 甲报数 countA++; numberA = (numberA % 20) + 1; // 保证在1~20之间循环 // 乙报数 countB++; numberB = (numberB % 30) + 1; // 保证在1~30之间循环 } std::cout << "同时报相同数字的次数: " << matchCount << std::endl; return 0; }