输入一个人的出生日期(包括年月日),将该生日中的年、月、日分别输出。
数据范围:年份满足
,月份满足
,日满足 
输入只有一行,出生日期,包括年月日,年月日之间的数字没有分隔符。
三行,第一行为出生年份,第二行为出生月份,第三行为出生日期。输出时如果月份或天数为1位数,需要在1位数前面补0。
20130225
year=2013 month=02 date=25
通过scanf函数的%m格式控制可以指定输入域宽,输入数据域宽(列数),按此宽度截取所需数据;通过printf函数的%0格式控制符,输出数值时指定左面不使用的空位置自动填0。
a = input()
print('year='+a[:4])
print('month='+a[4:6])
print('date='+a[6:8])
#include<iostream>
(720)#include<string>
using namespace std;
int main(){
string str;
while(cin>>str){
cout<<"year="<<str.substr(0,4)<<endl;
cout<<"month="<<str.substr(4,2)<<endl;
if(str.length()<8){
cout<<"date=0"<<str.substr(6,1)<<endl;
}else{
cout<<"date="<<str.substr(6,2)<<endl;
}
}
return 0;
} import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
String s = scanner.nextLine();
String year = s.substring(0, 4);
String month = s.substring(4, 6);
String days = s.substring(6, 8);
System.out.println("year="+year);
System.out.println("month="+month);
System.out.println("date="+days);
}
}
#include <stdio.h>
int main()
{
int year = 0;
int month = 0;
int date = 0;
//按照格式输入
scanf("%4d%2d%2d", &year, &month, &date);
printf("year=%4d\n", year);
printf("month=%02d\n", month);
printf("date=%02d\n", date);
return 0;
} n = input()
print(f'year={n[:4]}')
print(f'month={n[4:6]}')
print(f'date={n[6:]}') #include<stdio.h>
int main(void){
char year[10], month[5], date[5];
scanf("%4s%2s%2s", year, month, date);
printf("year=%s\nmonth=%s\ndate=%s", year, month, date);
return 0;
}
#include <iostream>
using namespace std;
int main() {
int num;
cin >> num;
cout << "year=" << num / 10000 << endl;
if (num / 100 % 100 < 10) {
cout << "month=" << 0 << num / 100 % 100 << endl;
}
else {
cout << "month=" << num / 100 % 100 << endl;
}
if (num % 100 < 10) {
cout << "date=" << 0 << num % 100 << endl;
}
else {
cout << "date=" << num % 100 << endl;
}
return 0;
}