当前位置:网站首页>scanf 格式化输入的一些问题
scanf 格式化输入的一些问题
2022-06-10 02:56:00 【.Ashy.】
1.scanf 的格式化输入
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m,n,q;
scanf("m=%dn=%dq=%d",&m,&n,&q);
printf("%d %d %d",m,n,q);
}
对于本程序,要想得到 1 2 3 则应该输入的内容是
A : m=1n=2q=3
B : m=1 n=2 q=3
C : m=1,n=2,q=3
D : 1 2 3
正确答案是 A
当没有空格的时候要严格按格式输入,不能多东西
2.对问题一的变式理解
当程序改为
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m,n,q;
scanf("m=%d n=%d q=%d",&m,&n,&q);
printf("%d %d %d",m,n,q);
}
当这样改之后 A,B 就都是正确答案了,要注意sacnf内的格式
总结1,2就是,只能少空格,不能多符号和空格
3.对scanf返回值的理解
scanf 返回值是一个很神奇的东西,它可以返回输入正确的类型的个数
例如
#include<bits/stdc++.h>
using namespace std;
int main()
{
int m,n,q;
cout<<scanf("%d %d %d",&m,&n,&q);
}
当输入1 2 3 输出值是 3
当输入1 2 c 输出值是 2
当输入1 c d 输出值是 1
当输入b c d 输出值是 0
可以用这个性质来判断输入的类型是否合法
scanf 返回值还可以用来多组输入
while(scanf("%d",&a)!=EOF)
{
}
这里EOF是 -1 ,只要有数据输入不管类型是否合法都返回非负数,故可以多组输入
当有多组输入时,以 Ctrl+z 结束输入
2022.5.26 Ashy
边栏推荐
- Xmake v2.6.6 发布,分布式编译和缓存支持
- golang微服务实例Protobuf和Grpc的使用
- Get the list of provinces and cities 【 project mall 】
- 取消打印Tensorflow中的无用信息,如tensorflow:AutoGraph could not transform <*> and will run it as-is、加载CUDA信息等
- Lua的模块和包
- leetcode:305. Number of islands
- ^28js is single threaded
- Postgresql中如何终止正在执行的查询
- ModuleNotFoundError: No module named ‘pip‘
- Introduction to 51 single chip microcomputer infrared communication
猜你喜欢

TS 23.122

Anaconda modify file save path

Arduino and processing serial port communication (split function)

qiankun 如何提取出公共的依赖库

样本方差分母为什么是n-1(无偏估计)?

Introduction to 51 single chip microcomputer infrared communication

重磅!DIY的Prometheus主备方案,全网唯一。生产未上,测试先行。

The local storage database SQLite of the uni app mobile terminal has no storage restrictions

Jupyter notebook configuring virtual environments

Pandas connection database read / write file
随机推荐
sql语句
Shift+ right mouse button No: Open command window here
promise 介绍和实现
2022.05 esp32 air upgrade OTA
MySQL 8.0.29 installation and configuration method graphic tutorial (Windows zip version)
Explain Seaborn in detail. Just read this one
86. (leaflet house) leaflet military plotting - collection of linear arrows
ModuleNotFoundError: No module named ‘pip‘
HCIE-Routing & Switching实验考试延期至2022年12月31日
JS内存泄漏
^27 timer related problems
There is a bug in the new document, or it may be stuck
ESP32 内部函数/变量无法跳转到定义
1px问题
Modify pycharm cache file path
Arduino and processing serial port communication (match function)
如何用Google Home音箱语音控制智汀家庭云设备?
1px problem
Wechat applet music playing code (playing mode, lyrics scrolling)
What should be paid attention to in the operation of official account retention?