当前位置:网站首页>Daily question - xiaolele changes the number
Daily question - xiaolele changes the number
2022-07-02 17:39:00 【Protect Xiaozhou】
The topic comes from niuke.com

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 ≤ 109)
Output description :
Output an integer , That is, the number obtained by xiaolele after modification .
Example 1
Input :
222222
Output :
0
Example 2
Input :
123
Output :
101
Thinking analysis :
First we enter an integer , Then we need to convert the even bits of the integer into 0, Odd digits become 1; Then it naturally involves retrieval conversion , Next, bloggers will share two ideas for solving problems .
The first is to use arrays , The advantage is data retrieval 、 It is easy to modify data , The disadvantage is that the program is cumbersome , Poor versatility , According to the instance , Make adjustments accordingly .
The second is making numbers , Through data retrieval , And then according to the question , Generate a new number , Until each item of the input integer is fetched , The new number is manufactured . Very easy to use .
Numeration method :
#include<stdio.h>
int main()
{
int a=0;// Integers a
int k=0;// Store the number of bits of each bit
int sum=0;// Make numbers
scanf("%d",&a);
// Define a i Used to control the data size of each bit , for example :123=1*100+2*10+3*1;
// The loop end condition is an integer a Everyone of has taken ;
//i*=10, amount to i=i*10; Because it's making numbers , So we should control the size of each bit
for(int i=1;a!=0;i*=10)
{
// And 10 You can get the last one by finding the module
k=a%10;
// Judge the parity of this bit
if(k%2==0)
{
k=0;// If it's even , Then this one is 0
sum+=k;
}
else
{
k=1;// If it's odd , Then this one is 1
sum+=k*i;// By riding i To adjust the size of digits , adopt sum Storage
}
// Divide 10, Remove the last digit from the approximate number , So we can judge the next
a=a/10;
}
// Print the number of manufacturing sum
printf("%d",sum);
return 0;
}Array method :
#include<stdio.h>
int main()
{
int i = 0, j = 0;
int t[16] = { 0 };
int n;
float sum = 0;
scanf("%d",&n);
while (n)
{
// Judge parity , And the corresponding treatment
if (n % 2 == 0||n==0)
{
t[i] = 0;
sum += t[i];
}
else
{
t[i] = 1;
sum += t[i];
}
++i;
n = n / 10;
}
// Every bit of the data is the same ( identical ) The situation of
if (sum /( i +1)== t[0])
printf("%d", t[0]);
// Data starts with 0, We output non 0 Future data
else if (t[i] == 0)
{
for (j = i; j >=0; j--)
{
if (t[j] % 2 != 0)
while (j >=0)
{
printf("%d", t[j]);
j--;
}
}
}
// Print the converted data
else
while (i>=0)
{
printf("%d",t[i]);
--i;
}
return 0;
}The topic comes from niuke.com :
Little Lele changed the number _ Niuke Tiba _ Cattle from
Thank you for watching this article , Please look forward to : Protect Xiao Zhou ღ
If there is infringement, please contact to modify and delete !
边栏推荐
- Introduction to nexus and detailed tutorial of Xiaobai using idea to package and upload to nexus3 private server
- si446使用记录(二):使用WDS3生成头文件
- 如何给 SAP Spartacus Storefront 创建新的页面
- Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
- 什么是敏捷开发流程
- uniapp H5页面调用微信支付
- Easyswoole3.2 restart failed
- Séparateur JS3 de niuke
- traceroute命令讲解
- Win10 system uses pip to install juypter notebook process record (installed on a disk other than the system disk)
猜你喜欢

Eth data set download and related problems

【网络是怎样连接的】第五章 探索服务器

Microservice architecture practice: Construction of scalable distributed database cluster

Experience home office, feel the completion of the project | community essay solicitation

Solution to the problem that the easycvr kernel of intelligent video analysis platform cannot be started as a service

Chrome browser quick access stackoverflow

What if the default browser cannot be set?
![链表求和[dummy+尾插法+函数处理链表引用常见坑位]](/img/08/30e8ca2376104d648a82dca8a72c42.png)
链表求和[dummy+尾插法+函数处理链表引用常见坑位]

Qwebengineview crash and alternatives

About me
随机推荐
VirtualLab基础实验教程-7.偏振(2)
How to create a new page for SAP Spartacus storefront
Example nonlinear integer programming
After meeting a full stack developer from Tencent, I saw what it means to be proficient in MySQL tuning
Si446 usage record (I): basic data acquisition
Smart trash can (V) - light up OLED
Introduce the scrollintoview() method attribute in detail
The difference of message mechanism between MFC and QT
[fluent] dart data type map type (create map set | initialize map set | traverse map set)
Chapter 3 of hands on deep learning - (1) linear regression is realized from scratch_ Learning thinking and exercise answers
si446使用记录(一):基本资料获取
CEPH principle
云通信接口更新迭代——SUBMAIL API V4正式上线
2022 interview questions
Chmod command principle and usage details [easy to understand]
Idea2021.1 installation tutorial
871. Minimum refueling times
What if the default browser cannot be set?
Dstat use [easy to understand]
USB interface powered Bluetooth color light strip controller