PAT 天梯赛 L1-042. 日期格式化 【水】

这篇博客主要解析PAT天梯赛中L1-042题目的日期格式化问题,包括题意理解、解题思路及AC代码分享。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题目链接

https://www.patest.cn/contests/gplt/L1-042

AC代码

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <cstdlib>
#include <ctype.h>
#include <numeric>
#include <sstream>
using namespace std;

typedef long long LL;
const double PI  = 3.14159265358979323846264338327;
const double E   = 2.718281828459;  
const double eps = 1e-6;
const int MAXN   = 0x3f3f3f3f;
const int MINN   = 0xc0c0c0c0;
const int maxn   = 1e5 + 5; 
const int MOD    = 1e9 + 7;

int main()
{
    int a, b, c;
    scanf("%02d-%02d-%04d", &a, &b, &c);
    printf("%04d-%02d-%02d\n",c, a, b);
}
### 关于L1-006 C++编程解 对于编号为L1-006的目,虽然提供的参考资料中并未直接提及该具体编号的内容[^1],但从常见的PAT (Programming Ability Test) 天梯赛型来看,这类目通常涉及基础算法和数据结构的应用。 #### 假设L1-006是一个关于字符串处理的问 如果假设L1-006涉及到的是一个简单的字符串操作问,比如统计特定字符的数量,则可以采用如下方式实现: ```cpp #include <iostream> using namespace std; int main() { string s; getline(cin, s); char targetChar; cin >> targetChar; int count = 0; for(char ch : s){ if(ch == targetChar){ ++count; } } cout << "Character '" << targetChar << "' appears " << count << " times." << endl; } ``` 这段代码首先读入一整行作为待分析的字符串`string s`,接着接收目标字符`char targetChar`用于匹配。遍历整个输入串并计数符合条件的字符数量最后输出结果。 #### 如果L1-006是有关日期转换的任务 另一种可能是此要求解析或格式化给定形式的时间戳。例如将形如“YYYYMM”的六位数字表示成更易读的形式:“YYYY-MM”。这可以通过下面的方法完成: ```cpp #include<iostream> using namespace std; int main(){ int x; cin>>x; int year=x/100; int month=x%100; // 对于两位数年份做适当调整 if(year<100){ if(year<22){ year+=2000; }else{ year+=1900; } } printf("%d-%02d",year,month); return 0; } ``` 上述程序片段展示了如何把紧凑格式的月份编码转化为标准的日历年月显示模式,并考虑到世纪转折时期的特殊情况[^5]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值