1.scanf(“%d/%d/%d”,&a,&b,&c)
这里如果输入02/02/02,a,b,c都被输入了2,忽略了0
来源: https://www.acwing.com/activity/content/code/content/7946218/
2。printf(“%d-%02d-%02d\n”,t/10000,t%10000/100,t%100);
来源: https://www.acwing.com/activity/content/code/content/7946218/
3.getcline和stringstream一起使用提取含有空格的字符串中的信息
基本格式
string s;
int a[N];
getline(cin,s);
stringstream ssin(s);
while(ssin>>a[i]) i++;
例子:
https://www.acwing.com/activity/content/code/content/7936273/
单词替换https://www.acwing.com/activity/content/code/content/7583534/
4.sscanf的使用——按格式读取字符串内的信息
sscanf(const char str, const char format, …)
#include <bits/stdc++.h>
using namespace std;
int main()
{
char a[20]="2004 2 21";
string b="2004 5 16";
int y1,m1,d1,y2,m2,d2;
sscanf(a,"%d %d %d",&y1,&m1,&d1);
sscanf(b.c_str(),"%d %d %d",&y2,&m2,&d2);
printf("%d %d %d\n%d %d %d",y1,m1,d1,y2,m2,d2);
//输出结果
2004 2 21
2004 5 16
return 0;
}
例子: https://www.acwing.com/activity/content/code/content/7951909/
5.cin读入十六进制
例子