网易2017年秋招编程题5
来源:互联网 发布:比特大陆 知乎 编辑:程序博客网 时间:2024/05/16 15:36
对于一个整数X,定义操作rev(X)为将X按数位翻转过来,并且去除掉前导0。例如:
如果 X = 123,则rev(X) = 321;
如果 X = 100,则rev(X) = 1.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
如果 X = 123,则rev(X) = 321;
如果 X = 100,则rev(X) = 1.
现在给出整数x和y,要求rev(rev(x) + rev(y))为多少?
C++ Code
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include <iostream>
int rev(int i)
{
int data[10];
int t = 0;
int j;
int result = 0;
while (i / 10 != 0)
{
if (i % 10 != 0)
data[t++] = i % 10;
i = i / 10;
}
data[t] = i;
for (j = 0; j <= t; j++)
{
result = result + data[j] * pow(10,t - j);
}
return result;
}
int main()
{
int m, n;
int result = 0;
printf("请输入m,n\n");
scanf("%d%d", &m,&n);
result = rev(rev(m) + rev(n));
printf("%d\n", result);
system("pause");
}
#include<stdlib.h>
#include<math.h>
#include <iostream>
int rev(int i)
{
int data[10];
int t = 0;
int j;
int result = 0;
while (i / 10 != 0)
{
if (i % 10 != 0)
data[t++] = i % 10;
i = i / 10;
}
data[t] = i;
for (j = 0; j <= t; j++)
{
result = result + data[j] * pow(10,t - j);
}
return result;
}
int main()
{
int m, n;
int result = 0;
printf("请输入m,n\n");
scanf("%d%d", &m,&n);
result = rev(rev(m) + rev(n));
printf("%d\n", result);
system("pause");
}
0 0
- 网易2017年秋招编程题5
- 2017网易实习生编程题
- 网易2017年秋招编程题之暗黑的字符串解析
- 网易2017年秋招编程题之暗黑的字符串
- 2017网易有道编程题:构造队列
- 网易2017秋招编程题
- 网易2017秋招编程题
- 网易2017秋招编程题
- 网易2017秋招编程题集合
- 2017网易秋招编程题7
- 网易2017秋招编程题8
- 网易2017秋招编程题2
- 网易2017秋招编程题6
- 网易2017秋招编程题1
- 2017网易有道校招三道编程题
- 网易2017秋招编程题集合
- 网易有道2017内推编程题
- 网易有道2017内推编程题
- 如何输入一个数,再原样输出出来。
- mvc(日志类)
- Java HashMap的死循环
- linux菜鸟入门之服务管理与软件包的安装
- 剑指offer:复杂链表的复制(java)
- 网易2017年秋招编程题5
- unity 同一张表中存入多种类型的数据时的解析方法
- UML——类图、对象图(静态图)
- 每月调仓投资策略--python
- Convert a Number to Hexadecimal
- C#文字阅读
- CentOS7 安装 nginx
- 关于计算机的网关问题
- Linux Mint 18(Ubuntu 16)安装f.lux教程