题解 | #出生日期输入输出#
出生日期输入输出
https://www.nowcoder.com/practice/4a4a9dd1edb6453ba4a0432319200743
#include <stdio.h>
#define A1(X) (1990 <= X && X <= 2015)
#define A2(X) (1 <= X && X <= 12)
#define A3(X) (1 <= X && X <= 30)
int main()
{
int a, b, c;
while (1)
{
if (scanf("%4d%2d%2d", &a, &b, &c) != 3)
{
printf("格式输入错误!\n");
while (getchar() != '\n');
printf("请重新输入\n");
}
else if (A1(a) && A2(b) && A3(c))
{
printf("year=%d\nmonth=%02d\ndate=%02d", a, b, c);
break;
}
else
{
printf("输入的年份月份或日期不在规定范围之间!\n");
while (getchar() != '\n');
printf("请重新输入\n");
}
}
return 0;
}
//代码应该还是有点问题 scanf读到8位数为止 也不会打印报错 因为是初学 先放在这吧 后面回头再来看看