B1022. D进制的A+B (20)

Description:

输入两个非负10进制整数A和B(<=230-1),输出A+B的D (1 < D <= 10)进制数。

Input:

输入在一行中依次给出3个整数A、B和D。

Output:

输出A+B的D进制数。

Sample Input:

123 456 8

Sample Output:

1103

 #include <cstdio>

 int main()
{
int a, b, d;
scanf("%d%d%d", &a, &b, &d); int sum = a+b;
int ans[], num = ;
do {
ans[num++] = sum%d;
sum /= d;
} while(sum != ); for(int i=num-; i>=; --i)
printf("%d", ans[i]); return ;
}

A1019. General Palindromic Number (20)

Description:

A number that will be the same when it is written forwards or backwards is known as a Palindromic Number. For example, 1234321 is a palindromic number. All single digit numbers are palindromic numbers.

Although palindromic numbers are most often considered in the decimal system, the concept of palindromicity can be applied to the natural numbers in any numeral system. Consider a number N > 0 in base b >= 2, where it is written in standard notation with k+1 digits ai as the sum of (aibi) for i from 0 to k. Here, as usual, 0 <= ai < b for all i and ak is non-zero. Then N is palindromic if and only if ai = ak-i for all i. Zero is written 0 in any base and is also palindromic by definition.

Given any non-negative decimal integer N and a base b, you are supposed to tell if N is a palindromic number in base b.

Input:

Each input file contains one test case. Each case consists of two non-negative numbers N and b, where 0 <= N <= 109 is the decimal number and 2 <= b <= 109 is the base. The numbers are separated by a space.

Output:

For each test case, first print in one line "Yes" if N is a palindromic number in base b, or "No" if not. Then in the next line, print N as the number in base b in the form "ak ak-1 ... a0". Notice that there must be no extra space at the end of output.

Sample Input1:

27 2

Sample Output1:

Yes
1 1 0 1 1

Sample Input2:

121 5

Sample Output2:

No

4 4 1

 #include <cstdio>

 #define MaxSize 50
int ans[MaxSize]; int main()
{
//freopen("E:\\Temp\\input.txt", "r", stdin); int N, b, num = ;
bool flag = true;
scanf("%d %d", &N, &b); do {
ans[num++] = N%b;
N /= b;
} while(N != ); for(int i=, j=num-; i<=(num-)/, j>=(num-)/; ++i, --j) {
if(ans[i] != ans[j]) {
flag = false;
break;
}
} if(flag == true) printf("Yes\n");
else printf("No\n");
for(int i=num-; i>=; --i) {
printf("%d", ans[i]);
if(i != ) printf(" ");
} return ;
}
 #include <cstdio>

 bool judge(int z[], int num)
{
for(int i=; i<=num/; ++i) {
if(z[i] != z[num--i]) return false;
else return true;
}
} int main()
{
int n, b, z[], num = ;
scanf("%d%d", &n, &b); do {
z[num++] = n%b;
n /= b;
} while(n != );
bool flag = judge(z, num); if(flag == true) printf("Yes\n");
else printf("No\n");
for(int i=num-; i>=; --i) {
printf("%d", z[i]);
if(i != ) printf(" ");
} return ;
}

A1027. Colors in Mars (20)

Description:

People in Mars represent the colors in their computers in a similar way as the Earth people. That is, a color is represented by a 6-digit number, where the first 2 digits are for Red, the middle 2 digits for Green, and the last 2 digits for Blue. The only difference is that they use radix 13 (0-9 and A-C) instead of 16. Now given a color in three decimal numbers (each between 0 and 168), you are supposed to output their Mars RGB values.

Input:

Each input file contains one test case which occupies a line containing the three decimal color values.

Output:

For each test case you should output the Mars RGB value in the following format: first output "#", then followed by a 6-digit number where all the English characters must be upper-cased. If a single color is only 1-digit long, you must print a "0" to the left.

Sample Input:

15 43 71

Sample Output:

#123456

 #include <cstdio>

 char radix[] = {'', '', '', '', '', '', '', '', '', '', 'A', 'B', 'C'};

 int main()
{
int r, g, b;
scanf("%d%d%d", &r, &g, &b); printf("#");
printf("%c%c", radix[r/], radix[r%]);
printf("%c%c", radix[g/], radix[g%]);
printf("%c%c", radix[b/], radix[b%]); return ;
}

A1058. A+B in Hogwarts (20)

Description:

If you are a fan of Harry Potter, you would know the world of magic has its own currency system -- as Hagrid explained it to Harry, "Seventeen silver Sickles to a Galleon and twenty-nine Knuts to a Sickle, it's easy enough." Your job is to write a program to compute A+B where A and B are given in the standard form of "Galleon.Sickle.Knut" (Galleon is an integer in [0, 107], Sickle is an integer in [0, 17), and Knut is an integer in [0, 29)).

Input:

Each input file contains one test case which occupies a line with A and B in the standard form, separated by one space.

Output:

For each test case you should output the sum of A and B in one line, with the same format as the input.

Sample Input:

3.2.1 10.16.27

Sample Output:

14.1.28

 #include <cstdio>

 int main()
{
int a[], b[], c[];
scanf("%d.%d.%d %d.%d.%d", &a[], &a[], &a[], &b[], &b[], &b[]); int carry = ;
c[] = (a[]+b[])%;
carry = (a[]+b[])/;
c[] = (a[]+b[]+carry)%;
carry = (a[]+b[]+carry)/;
c[] = a[]+b[]+carry; printf("%d.%d.%d", c[], c[], c[]); return ;
}

PAT/进制转换习题集的更多相关文章

  1. PAT甲级 进制转换题_C++题解

    进制转换题 PAT (Advanced Level) Practice 进制转换题 目录 <算法笔记> 重点摘要 1015 Reversible Primes (20) 1019 Gene ...

  2. SQL Server 进制转换函数

    一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...

  3. [No000071]C# 进制转换(二进制、十六进制、十进制互转)

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  4. JS中的进制转换以及作用

    js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现: //10进制转为16进制 ().toString() // =>&q ...

  5. 结合stack数据结构,实现不同进制转换的算法

    #!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...

  6. 进制转换( C++字符数组 )

    注: 较为简便的方法是用 整型(int)或浮点型(long.double 注意:该类型不一定能够准确存储数据) 来存放待转换的数值,可直接取余得到每一位数值 较为稳定的方法是用 字符数组储存待转换的数 ...

  7. JS 进制转换

    十进制转换成其他进制 objectname.toString([radix])   objectname 必选项.要得到字符串表示的对象. radix 可选项.指定将数字值转换为字符串时的进制. 例如 ...

  8. php的进制转换

    学习了php的进制转换,有很多的知识点,逻辑,也有最原始的笔算,但是我们还是习惯使用代码来实现进制的转换,进制的转换代码有如下:二进制(bin)八进制( oct)十进制( dec)十六进制( hex) ...

  9. C++ 中数串互转、进制转换的类

    /******************************************************************** created: 2014/03/16 22:56 file ...

随机推荐

  1. EF MYSQL 不能选择实体框架版本

    web.config文件里面加如下配置,然后编译 <provider invariantName="MySql.Data.MySqlClient" type="My ...

  2. Getting Started With Hazelcast 读书笔记(第八章-第十章)

    第八章到第十章就是一些介绍性的描述,吹的就是Hazelcast能使用在各种地方..   第八章 -从外面看 1.Hazelcast做了一个memcache的java实现,方便py和php使用. 2.可 ...

  3. tfs 删除工作区

    公司员工离职后,有部分文件迁出,有没有tfs密码的情况下,考虑删除工作区,在网上找到方法实践有效,在次记录下. 在命令提示行下进入 “...\Microsoft Visual Studio 8\Com ...

  4. [front]有效开展一个前端项目

    今天的前端如果没有用到 npm,效率是比较低的:所以要从使用的工具来讲. 1. 一切都依赖于 nodejs: 下载一个 linux 的源码包就可以开始安装了. $ wget https://nodej ...

  5. Servlet下载文件和http响应

    下载文件等: 1.得到公共的内容ServletContext sc = this.getServletContext(); 2.在链接名字后面加个? 一个参数?参数1=值 两个参数?参数1=值& ...

  6. Linux下chkconfig命令详解

    chkconfig命令主要用来更新(启动或停止)和查询系统服务的运行级信息.谨记chkconfig不是立即自动禁止或激活一个服务,它只是简单的改变了符号连接. 使用语法:chkconfig [--ad ...

  7. IIS7.5 由于 Web 服务器上的“ISAPI 和 CGI 限制”列表设置,无法提供您请求的页面

    IIS7.5中将一网站应用程序池托管管道模式改为经典后,网站页面打不开,错误信息: 引用内容 HTTP 错误 404.2 - Not Found由于 Web 服务器上的“ISAPI 和 CGI 限制” ...

  8. yaf框架学习笔记

    1.yaf框架支持简单的试图引擎,并且支持用户自定义视图引擎,比如smarty. 2.Yaf_Request_Http::getQuery  ,Yaf_Request_Http::getQuery ( ...

  9. Android之ListView——ArrayAdapter的用法学习

    当我们使用ListView时,必不可少的便会使用到adapter,adapter的用处就像是一个水管接口,把你想展现的数据与你希望展现的布局样式通过某种协定结合起来. ArrayAdapter针对每个 ...

  10. Android 时间维护服务 TimeService(针对于特殊定制设备)

    此方法针对于无法自动获取网络时间的特殊设备,正常 Android 设备直接调用 System.currentTimeMillis(); 方法获取当前时间即可. TimeService 集成于 Serv ...