PAT/进制转换习题集
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/进制转换习题集的更多相关文章
- PAT甲级 进制转换题_C++题解
进制转换题 PAT (Advanced Level) Practice 进制转换题 目录 <算法笔记> 重点摘要 1015 Reversible Primes (20) 1019 Gene ...
- SQL Server 进制转换函数
一.背景 前段时间群里的朋友问了一个问题:“在查询时增加一个递增序列,如:0x00000001,即每一个都是36进位(0—9,A--Z),0x0000000Z后面将是0x00000010,生成一个像下 ...
- [No000071]C# 进制转换(二进制、十六进制、十进制互转)
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- JS中的进制转换以及作用
js的进制转换, 分为2进制,8进制,10进制,16进制之间的相互转换, 我们直接利用 对象.toString()即可实现: //10进制转为16进制 ().toString() // =>&q ...
- 结合stack数据结构,实现不同进制转换的算法
#!/usr/bin/env python # -*- coding: utf-8 -*- # learn <<Problem Solving with Algorithms and Da ...
- 进制转换( C++字符数组 )
注: 较为简便的方法是用 整型(int)或浮点型(long.double 注意:该类型不一定能够准确存储数据) 来存放待转换的数值,可直接取余得到每一位数值 较为稳定的方法是用 字符数组储存待转换的数 ...
- JS 进制转换
十进制转换成其他进制 objectname.toString([radix]) objectname 必选项.要得到字符串表示的对象. radix 可选项.指定将数字值转换为字符串时的进制. 例如 ...
- php的进制转换
学习了php的进制转换,有很多的知识点,逻辑,也有最原始的笔算,但是我们还是习惯使用代码来实现进制的转换,进制的转换代码有如下:二进制(bin)八进制( oct)十进制( dec)十六进制( hex) ...
- C++ 中数串互转、进制转换的类
/******************************************************************** created: 2014/03/16 22:56 file ...
随机推荐
- 【待整理】Linux故障排查
ethtool -i eth0dmidecode -i eth3more /var/log/meclogmore /etc/issue
- 消除a标签点击后产生的虚线框
为a标签添加这条属性: a:focus {outline:none;-moz-outline:none;}
- Oracle查询某段日期内某个时间段的数据
示例: 查询最近一周12:30分到13:00这段时间内的订单量: SELECT * FROM T_ORDER O WHERE O.CREATEDATETIME BETWEEN SYSDATE AND ...
- 2-4. Using auto with Functions
在C++14中允许使用type deduction用于函数参数和函数返回值 Return Type Deduction in C++11 #include <iostream> using ...
- aa2
option = { series : [ { name: 'Map', type: 'map', mapLocation: { x : 'left', y : 'top', height : 500 ...
- MySQL创建一个具有root权限的用户
grant all privileges on *.* to 'user'@'host' identified by 'password' WITH GRANT OPTION MAX_QUERIES_ ...
- C++写一个带参数运行的程序
#include <string.h>#include <iostream>#include <cstdlib>using namespace std; int m ...
- ASP.NET ashx实现无刷新页面生成验证码
现在大部分网站登陆时都会要求输入验证码,在网上也看了一些范例,现在总结一下如何实现无刷新页面生成验证码. 效果图: 实现方式: 前台: <div> <span>Identify ...
- 如何用VB.Net创建一个三层的数据库应用程序
[b]1.[/b][b]概论:[/b] 本文将介绍如何创建一个三层应用程序,并且将介绍如何创建一个Web Service服务. ADO.NET创建Windows三层结构应用程序的体系架构如下图所示: ...
- 简单的dp
有趣的数:(动态规划,状态转移) #include<stdio.h> ][]; int main() { int n,i; ; i<; i++) dp[i][]=; while(~s ...