解题思路:
%d表示打印整型的,
%2d表示把整型数据打印最低两位,
%02d表示把整型数据打印最低两位,如果不足两位,用0补齐
参考代码:
#include<bits/stdc++.h> using namespace std; struct data { int day; int month; int year; }d[100]; bool cmp(struct data& a, struct data& b) { if (a.year < b.year) return true; else if (a.year == b.year) { if (a.month < b.month) return true; else if (a.month = b.month) { if (a.day < b.day) return true; else return false; } else return false; } else return false; } /* bool cmp(struct data a,struct data b) { if(a.year==b.year) { if(a.month==b.month) { return a.day<b.day; } else return a.month<b.month; } else return a.year<b.year; } */ int main() { int i = 0; while (scanf("%d/%d/%d", &d[i].month, &d[i].day, &d[i].year) != EOF) { i++; } sort(d, d + i, cmp); for (int j = 0; j < i; j++) { printf("%02d/%02d/%d\n", d[j].month, d[j].day, d[j].year); } }
0.0分
2 人评分
最小公倍数 (C语言代码)浏览:861 |
简单的for循环浏览:1408 |
C语言程序设计教程(第三版)课后习题8.8 (C语言代码)浏览:853 |
printf基础练习2 (C语言代码)浏览:617 |
C语言程序设计教程(第三版)课后习题3.7 (C语言代码)浏览:561 |
字符串比较 (C语言代码)浏览:679 |
分解质因数 (C++代码)浏览:1469 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:598 |
纪念品分组 (C++代码)浏览:834 |
简单的a+b (C语言代码)浏览:242 |