#include<stdio.h>
int main()
{
int year = 0;
int month = 0;
int day = 0;
scanf("%d %d %d", &year, &month, &day);
printf("%d-%d-%d\n", year, month, day);
return 0;
}
上述代码只能用
2024 1 22
输入
用其他形式就会错
#include<stdio.h>
int main()
{
int year=0;
int month = 0;
int day = 0;
scanf("%d%*c%d%*c%d", &year, &month, &day);
printf("%d-%d-%d\n", year, month, day);
return 0;
}
scanf用了%*c连接%d
输入用
2024 1 22
或
2024-1-22
或
2024 1 22
都会输出
2024-1-22
以上