PAT : L1-062 幸运彩票 (15 分) 题解

L1-062 幸运彩票 (15 分)
彩票的号码有 6 位数字,若一张彩票的前 3 位上的数之和等于后 3 位上的数之和,则称这张彩票是幸运的。本题就请你判断给定的彩票是不是幸运的。

输入格式:
输入在第一行中给出一个正整数 N(≤ 100)。随后 N 行,每行给出一张彩票的 6 位数字。

输出格式:
对每张彩票,如果它是幸运的,就在一行中输出 You are lucky!;否则输出 Wish you good luck.

输入样例:
2
233008
123456
输出样例:
You are lucky!
Wish you good luck.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <memory.h>
#include <time.h>
#include <windows.h>
#include <windows.h>
#include <ctype.h>
int main()
{
    int cases;
    scanf("%d", &cases);
    getchar();
    while (cases--)
    {
        char num[7];
        gets(num);
        if (num[0] + num[1] + num[2] == num[3] + num[4] + num[5])
            printf("You are lucky!");
        else
            printf("Wish you good luck.");
        printf("\n");
    }
    return 0;
}
发布了30 篇原创文章 · 获赞 43 · 访问量 10万+

猜你喜欢

转载自blog.csdn.net/qq_43041976/article/details/88947038