当前位置:网站首页>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 !
边栏推荐
- The construction of scalable distributed database cluster and the partition design of oneproxy sub database
- 牛客 JS3 分隔符
- 维护万星开源向量数据库是什么体验
- class和getClass()的区别
- Alibaba Tianchi SQL learning notes - Day3
- Nexus簡介及小白使用IDEA打包上傳到Nexus3私服詳細教程
- 线性规划例题 投资的收益与风险
- Easyswoole3.2 restart failed
- Use of nexttile function in MATLAB
- chmod命令原理及用法详解[通俗易懂]
猜你喜欢
![[fluent] dart data type map type (create map set | initialize map set | traverse map set)](/img/02/75d21470ea0ae4cd3d17696a93d1ca.jpg)
[fluent] dart data type map type (create map set | initialize map set | traverse map set)

Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!

About me

Listing of chaozhuo Aviation Technology Co., Ltd.: raising 900million yuan, with a market value of more than 6billion yuan, becoming the first science and technology innovation board enterprise in Xia

例题 非线性整数规划

线性规划例题 投资的收益与风险

Microservice architecture practice: using Jenkins to realize automatic construction

Are you holding back on the publicity of the salary system for it posts such as testing, development, operation and maintenance?

Easyswoole3.2 restart failed
![List summation [dummy+ tail interpolation + function processing list reference common pit]](/img/08/30e8ca2376104d648a82dca8a72c42.png)
List summation [dummy+ tail interpolation + function processing list reference common pit]
随机推荐
Leetcode question brushing record | 933_ Recent requests
Ssm+ wechat applet to realize property management system
Income and risk of linear programming example investment
Migrate your accelerator based SAP commerce cloud storefront to Spartacus
uva1169
ROS knowledge points -- the difference between ros:: nodehandle N and NH ("~")
IPtables中SNAT、DNAT和MASQUERADE的含义
Microservice architecture practice: Construction of highly available distributed file system fastdfs architecture
Niuke js3 separator
Goodbye, shucang. Alibaba's data Lake construction strategy is really awesome!
Platform management background and business menu resource management: business permissions and menu resource management design
[非线性控制理论]8_三种鲁棒控制器的比较
dstat使用[通俗易懂]
executescalar mysql_ExecuteScalar()
The beginning of life
SAP commerce cloud storefront framework selection: accelerator or Spartacus?
Wechat applet - arrows floating up and down
PCL知识点——体素化网格方法对点云进行下采样
USB interface powered Bluetooth color light strip controller
VirtualLab基础实验教程-7.偏振(1)