当前位置:网站首页>【码蹄集新手村 600 题】格式化的输入输出,使用 0 来代替补全的空格
【码蹄集新手村 600 题】格式化的输入输出,使用 0 来代替补全的空格
2022-07-17 18:23:00 【Sandm *】
题目链接:
解题思路:
因为题目中要求在输出的数值前面,如果有多余空格的话要使用 0 来补全
补全方法:
这里尽量使用 C 语言中的 printf ( ) 函数,
因为可以格式化控制输入输出的格式,
而 C++ 中的输入输出流则不具备该种功能,
虽然可以实现,
但是相对而言较为复杂
即:
%0nd
这里的 0 就是使用数字 0 来代替空格
参考代码:
#include<bits/stdc++.h>
using namespace std;
int main( )
{
int year = 0,month = 0,date = 0;
//cin >> month >> "/" >> date >> "/" >> year ;
/*不可以使用上面的方式输入 / */
scanf("%d/%d/%d",&month,&date,&year);
printf("%04d%02d%02d",year,month,date);
return 0;
}
边栏推荐
- 忘掉Postman,Apifox更好用
- Metal organic framework material / polymer composite zif-8/p (TDA co HDA) | zinc oxide [email protected] (FE) composite nan
- LeetCode 0117. Populate the next right node pointer II of each node
- Perl command batch replaces some contents in the file
- [JS reverse crawler] - Youdao translation JS reverse practice
- 大气非等晕效应
- npm err! [email protected] build: `umi build`
- 【js逆向爬虫】-有道翻译js逆向实战
- 弘业期货网上开户安全吗?有没有开户指引?
- How to upgrade Flink job gracefully?
猜你喜欢
How to upgrade Flink job gracefully?
codeforce:A. Difference Operations【数学思维】
Visual ETL tool kettle concept, installation and practical cases
MOF customized materials | ultra thin MOF nanobelts | magnetic Fe3O4 @cd-mof nanocomposites | zif-8/ graphene composite nanoparticles
Forget about postman. Apifox is better
Panasonic A6 servo driver external absolute value grating ruler full closed loop parameter setting
jvm自学总结
VMware imports ova/ovf virtual machine files
The latest Jilin construction safety officer simulation question bank and answers in 2022
STM32F1与STM32CubeIDE编程实例-MPU-6050 六轴(陀螺仪 + 加速度计)驱动
随机推荐
OSSImport迁移之路
El table column drag and drop (no need to introduce other plug-ins)
[record of question brushing] 13 Roman numeral to integer
Metal organic framework / nitrogen carbide nano sheet (uio-66/hocn) composite | mil-101 loaded Au Pd alloy nanoparticles | chemical reagent MOF customization
Array simulation queue
Advanced C language -- character function and string function
codeforce:G. Good Key, Bad Key【贪心】
Method of converting video format to ffmpeg and exporting GIF dynamic graph
onvif协议相关:3.1.1 Digest方式获取Authorization
时序逻辑与组合逻辑的reg
Attachment handling of SAP Fiori
jvm自学总结
Metal organic framework material / polymer composite zif-8/p (TDA co HDA) | zinc oxide [email protected] (FE) composite nan
VMware imports ova/ovf virtual machine files
Codeforce:g. good key, bad key [greed]
How to add a thread in MFC
使用case语句时会产生锁存器的情况
Li Kou 413 division of equal difference sequence dynamic programming
[Tencent blue whale] the seventh 7.24 operation and maintenance day holiday greetings ~ come and make a wish~
Visual ETL tool kettle concept, installation and practical cases