当前位置:网站首页>【码蹄集新手村 600 题】计算一个整数有多少位数
【码蹄集新手村 600 题】计算一个整数有多少位数
2022-07-17 18:23:00 【Sandm *】
题目如下:

解题思路:
利用 while 循环与运算符 / 去解决
注意点:
要对数据分俩种情况讨论,
如果不加以判断
当测试的数据为数字 0 时,所给出的位数为 0 ,而不是 1
参考代码:
#include<bits/stdc++.h>
using namespace std;
int main( )
{
int data = 0;
cin >> data;
int count = 0;
if(data == 0)
{
count++;
}
else
{
while(data)//当所给数字为0时程序所给出的位数为0,而不是1
{
data = data / 10;
count++;
}
}
cout << count;
return 0;
}边栏推荐
- How to add a thread in MFC
- Hello, everyone. How to synchronize binlog in real time before the database starts? Is there a good scheme
- Unveiling secrets of matrixcube 101 - functions and architecture of matrixcube
- 动手学深度学习(第二版)注释后代码【持续更新】
- Panasonic A6 servo driver external absolute value grating ruler full closed loop parameter setting
- Azkaban installation documentation
- Reg of sequential logic and combinatorial logic
- 【腾讯蓝鲸】第七届 7·24 运维日节日祝福送上~ 快来许愿~
- [try to hack] ARP and ARP deception
- S32K148_CAN驱动(裸机开发)
猜你喜欢

onvif协议相关:3.1.2 Digest方式获取token列表

Advanced C language -- character function and string function

onvif协议相关:3.1.3 Digest方式获取截图url

2.三数之和

torch.utils.data.DataLoader说明

onvif协议相关:3.1.4 Digest方式获取流地址

Qt之使用QLisView实现QQ登录历史列表

codeforce:A. Difference Operations【数学思维】
[email protected] Cobalt iron bimetallic organic skeleton cox/mil-100 (FE) | [email protected]

Li Kou 70 - climbing stairs - Dynamic Planning
随机推荐
Chitosan coated pcn224 nanoparticles | metal organic skeleton fe-mil-88nh2 | nickel based MOF material (Ni MOF / NF)
Hello, everyone. How to synchronize binlog in real time before the database starts? Is there a good scheme
onvif协议相关:常用类说明
STL string查找子串
【刷题记录】13. 罗马数字转整数
力扣413-等差数列划分——动态规划
The latest Jilin construction safety officer simulation question bank and answers in 2022
onvif协议相关:4.1.1 WS-Username token方式获取WSUsernameTokenBean
响应式织梦模板物流货运服务类网站
Computer dial-up Internet access
忘掉Postman,Apifox更好用
【腾讯蓝鲸】第七届 7·24 运维日节日祝福送上~ 快来许愿~
npm err! [email protected] build: `umi build`
Ossimport migration path
[pumpkin Book ml] (task2) mathematical derivation of linear model (least squares estimation, generalized Rayleigh quotient, maximum likelihood estimation, etc.)
MOF customized material | NH (2) -uio66/rgo Graphene Oxide Nanocomposite | methylene blue loaded zif-90 nanoparticles
CMOS switch learning (I)
perl 命令批量替换文件中的一些内容
STL string复制比较
JVM self study summary