2108 - 中大奖
时间限制 : 1 秒
内存限制 : 32 MB
小明有一天做梦梦见自己买的双色球彩票中奖了,于是第二天他马上去买了一注双色球。双色球的玩法是从1~33这33个红球中选择6个不同的号码球,再从1~16这16个蓝球中选择1个号码球,这7个号码构成一注。双色球的中奖规则如下:
一等奖:7个球全中
二等奖:中6个红球,蓝球没中
三等奖:中5个红球和蓝球
四等奖:中5个红球,蓝球没中,或者中4个红球和蓝球
五等奖:中3个红球和蓝球,或者中4个红球,蓝球没中
六等奖:中2个红球和蓝球,或者中1个红球和蓝球,或者只中了蓝球,没中红球
现在告诉你小明买的投注号码,请你编程告诉他中没中奖。
题目输入
输入包含多组测试数据。
每组第一行输入7个正整数,表示小明买的号码,前6个是红球的号码,最后一个是蓝球的号码。
每组第二行也输入7个正整数,表示开奖号码,前6个是红球的号码,最后一个是蓝球的号码。
所有号码均在题目描述中的相应的范围内,输入中红球的号码一定是按照升序排序的。
题目输出
对于每组输入,如果小明中奖了,则输出对应的获奖等级,用阿拉伯数字表示,例如小明中了一等奖,则输出1,中了二等奖,则输出2,以此类推。如果小明没中奖,则输出“Poor Xiaoming”(引号不输出)。
输入/输出样例
输入格式
1 8 11 12 26 27 9 1 8 11 12 26 27 9 1 2 3 4 5 6 7 1 2 9 10 11 12 7 7 10 15 16 31 33 15 7 11 15 18 32 33 18
输出格式
1 6 Poor Xiaoming
C语言解答
#include <stdio.h> int main() { int r,b,i,j; int a[10],c[10]; while(scanf("%d",&a[0])!=EOF) { r=0; b=0; for(i=1;i<7;i++) scanf("%d",&a[i]); for(i=0;i<7;i++) scanf("%d",&c[i]); for(i=0;i<6;i++) { for(j=0;j<6;j++) { if(a[i]==c[j]) { r++; } } } if(a[6]==c[6]) b=1; if(b==1) { switch(r) { case 6:printf("1\n");break; case 5:printf("3\n");break; case 4:printf("4\n");break; case 3:printf("5\n");break; case 2: case 1: case 0:printf("6\n"); } } else { switch(r) { case 6:printf("2\n");break; case 5:printf("4\n");break; case 4:printf("5\n");break; case 3: case 2: case 1: case 0:printf("Poor Xiaoming\n"); } } } return 0; }
C++解答
#include<iostream> #include<cstdio> using namespace std; int main() { int a[10],b[10],aa,bb; while(scanf("%d",&a[0])!=EOF) { for(int i=1;i<6;i++)scanf("%d",&a[i]); scanf("%d",&aa); for(int i=0;i<6;i++)scanf("%d",&b[i]); scanf("%d",&bb); int i=0,j=0; int cnt=0; while(i<6&&j<6) { if(a[i]==b[j]) { cnt++; i++; j++; } else if(a[i]>b[j]) { j++; } else if(a[i]<b[j]) { i++; } } if(cnt==6&&aa==bb)cout<<1<<endl; else if(cnt==6&&aa!=bb)cout<<2<<endl; else if(cnt==5&&aa==bb)cout<<3<<endl; else if((cnt==5)||(cnt==4&&aa==bb))cout<<4<<endl; else if((cnt==3&&aa==bb)||cnt==4)cout<<5<<endl; else if((cnt==2&&aa==bb)||(cnt==1&&aa==bb)||(aa==bb))cout<<6<<endl; else cout<<"Poor Xiaoming"<<endl; } return 0; }
Java解答
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc=new Scanner(System.in); while(sc.hasNext()) { int[] a=new int[7]; int[] b=new int[7]; int s1=0,s2=0; for(int i=0;i<7;i++) a[i]=sc.nextInt(); for(int i=0;i<7;i++) b[i]=sc.nextInt(); for(int i=0;i<6;i++) { for(int j=0;j<6;j++) { if(a[i]==b[j]) { s1++;break; } } } if(a[6]==b[6]) s2++; if(s1==6&&s2==1) System.out.println(1); else if(s1==6&&s2==0) System.out.println(2); else if(s1==5&&s2==1) System.out.println(3); else if((s1==5&&s2==0)||(s1==4&&s2==1)) System.out.println(4); else if((s1==4&&s2==0)||(s1==3&&s2==1)) System.out.println(5); else if(s2==1) System.out.println(6); else System.out.println("Poor Xiaoming"); } sc.close(); } }