解题思路:
枚举类型,switch分支,循环输入
注意事项:
switch的break不要漏掉
参考代码:
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <vector> #include <algorithm> #include <stdio.h> #define N 7 using namespace std; enum Prize { NON = 0, SIX = 1, FIVE, FOUR, THREE, TWO, ONE, SPEC }; vector<int> winLott;//中奖彩票 int lott[N]; //当前彩票 int winCount[N]; //中奖彩票数量 Prize checkLott() { int samNum = 0; for (int i = 0; i < N; i++) samNum += count(winLott.begin(), winLott.end(), lott[i]); Prize p = (Prize)samNum; return p; } int main(int argc, char** argv) { int lotteryCount = 0; cin >> lotteryCount; //输入中奖彩票 for (int i = 0; i < N; i++) { int temp = 0; cin >> temp; winLott.push_back(temp); } //输入并处理彩票 for (int i = 0; i < lotteryCount; i++) { //输入一张彩票 for (int j = 0; j < N; j++) cin >> lott[j]; switch (checkLott()) { case SPEC: winCount[0] += 1; break; case ONE: winCount[1] += 1; break; case TWO: winCount[2] += 1; break; case THREE: winCount[3] += 1; break; case FOUR: winCount[4] += 1; break; case FIVE: winCount[5] += 1; break; case SIX: winCount[6] += 1; break; default: break; } memset(lott, 0x00, sizeof(lott)); } for (int i = 0; i < N; i++) cout << winCount[i] << " "; cout << endl; return 0; }
0.0分
0 人评分
C语言训练-8除不尽的数 (C语言代码)浏览:825 |
C语言程序设计教程(第三版)课后习题8.4 (C++代码)浏览:639 |
汽水瓶 (C++代码)浏览:839 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:854 |
C语言程序设计教程(第三版)课后习题9.1 (C++代码)浏览:610 |
点我有惊喜!你懂得!浏览:1439 |
C语言程序设计教程(第三版)课后习题10.2 (C语言代码)浏览:1152 |
C语言程序设计教程(第三版)课后习题8.1 (Java代码)浏览:828 |
简单的a+b (C语言代码)浏览:564 |
【金明的预算方案】 (C++代码)浏览:873 |