当前位置:网站首页>Bc116 xiaolele changed to digital
Bc116 xiaolele changed to digital
2022-06-23 01:41:00 【'Dream_】
( come from Cattle from Beginner programming training )
1. problem :
( Link up : Change the number )
describe
Little Lele likes numbers , Especially like 0 and 1. He now has a number , I want to change the number of each person into 0 or 1. If a bit is odd , Just turn it into 1, If it's even , Then turn it into 0. Please answer what he finally got .
Input description :
Input contains an integer n (0 ≤ n ≤ 10^9)
Output description :
Output an integer , That is, the number obtained by xiaolele after modification .
Example 1
Input :
222222Output :
0
2. Ideas :
First Enter an integer , According to the meaning , need Use / and % as well as while loop The whole number is divided into numbers for odd and even judgment (()%2 whether ==0), if Odd numbers make the new variable 1, Even numbers are 0
secondly The main point is The presentation of the final number is an integer of the final variables of each digit , So you need an integer output at this time ( Instead of outputting as an array !), This Integer source On : The resulting number on each bit *pow And to present , and pow The power number is required ( Number of digits -1), The number of digits is count Record
3. Code :
#include<stdio.h>
#include<math.h>
int main()
{
long int n = 0;
//printf(" Please enter an integer n:");
scanf("%ld", &n);
//long int ret=Change(n);
//printf(" The result is :");
long int m = 0;
long int sum = 0;
long int ret = 0;
float count = 0;
while(n)// Use it carefully while use for You need to know how many numbers an integer consists of We need to ask for it again
{
m = n % 10;// Start with the last one
n /= 10;
if (0 == (m % 2))// even numbers - It can be 2 to be divisible by Remainder is 0!
{
count++;
ret = 0;
sum += ret*(long int )(pow(10, (count - 1)));// Pay attention to the combination : No arrays It is calculated in exponential form !!
//pow(float x,float y)
}
else
{
count++;
ret = 1;
sum += ret * (long int)(pow(10, (count - 1)));
}
}
printf("%ld\n", sum);
return 0;
}4. Be careful :
pow(float x, float y) float form , So this problem involves cast !
边栏推荐
- 人民币的单位的大写
- Debian10 configuring rsyslog+loganalyzer log server
- E-R图
- 关于打算做一个web的问题看板,需要使用哪些方面语言及数据库知识!
- SYSTEMd summary
- The devil cold rice # 099 the devil said to travel to the West; The nature of the boss; Answer the midlife crisis again; Specialty selection
- 崔鹏团队:万字长文梳理「稳定学习」全景图
- SQL programming task03 job - more complex query
- Debian10 create users, user groups, switch users
- How are pub and sub connected in ros1?
猜你喜欢

The devil cold rice # 099 the devil said to travel to the West; The nature of the boss; Answer the midlife crisis again; Specialty selection

Module 8 job

Unique in Pimpl_ PTR compilation errors and Solutions

Installing MySQL for Linux

How are pub and sub connected in ros1?

Wallys/DR7915-wifi6-MT7915-MT7975-2T2R-support-OpenWRT-802.11AX-supporting-MiniPCIe

Use elk to save syslog, NetFlow logs and audit network interface traffic
![[hdu] P6964 I love counting](/img/ff/f8e79d28758c9bd3019816c8f46723.png)
[hdu] P6964 I love counting

ERROR { err: YAMLException: end of the stream or a document separator is expected at line 6, colum

Steps to implement a container global component
随机推荐
3D printing microstructure
Charles garbled code problem solving
An interesting example of relaxed memory models
B tree and b+ tree
Day500: keyboard line
Browser independent way to detect when image has been loaded
Xiaobai operates win10 to expand Disk C (allocate disk D memory to Disk C) and the test is valid for many times
Modulenotfounderror: no module named 'rospy', PIP could not find the installation package
Vector 2 (friend and copy construction)
278. digital combination
Char[], char *, conversion between strings
Extend your kubernetes API using the aggregation API
Get the direction of mouse movement
Day575: divide candy
SQL programming task05 job -sql advanced processing
Add / get and delete cookies
[learning notes] roll back Mo team
Up the Strip
Vector 3 (static member)
Real topic of the 2020 Landbridge cup provincial competition - go square (dp/dfs)