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 ...
随机推荐
- xlrd读取多个excel电子表数据
import sys import xlrd import traceback def ReadData(FileName): try: workBook = xlrd.open_workbook(F ...
- Mac删除.DS_Store文件
1.删除.DS_Store文件 sudo find ./ -name ".DS_Store" -depth -exec rm {} \; 2.禁止生成此文件 defaults wr ...
- WPF 中使用MVVM模式后,找回ListBox中的ListBoxItem元素
ListBoxItem lstitem = this.list.ItemContainerGenerator.ContainerFromItem(m) as ListBoxItem; 其中this.l ...
- css 等高布局
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- flask-admin章节四:flask session的使用
1. 关于session flask session可能很多人根本都没有使用过,倒是cookie大家可能使用得比较多.flask cookie使用起来比较简单,就两个函数,读取和设置. 具体使用方式如 ...
- flask-admin众博客概述
最近用flask admin(https://flask-admin.readthedocs.org/en/latest/)构建自动化发布平台,发现flask admin蛮强大的,基本上不需要自己写太 ...
- Bootstrap组件
1.Bootstrap组件——Glyphicons图标字体 图标字体:可以表示的文字不是abcd或1234,而是一个又一个图形符号,比直接使用图片好处:可以任意放大不会失真:所有能使用文字的地方都可以 ...
- map阶段动态获取CombineTextInputFormat各输入文件路径
老mr程序中map中conf的map.input.file参数只能获取获取CombineTextInputFormat的第一个输入文件,而新版mr程序则连第一个输入文件也无法获取,这是因为create ...
- 关于windows下QT以及QT creator的安装
普及 之 windows下qt的安装及配置 qt介绍 : Qt,分为商业.开源两个版本,商业版需要花钱购买license,而开源版本则遵守GPL协议,提供了源码,用户需要自行编译,才能生产动态 ...
- html input的file文件输入框onchange事件触发一次失效解决方法
最近在做一个图片上传的功能,出现提交一次后,file输入框的change事件无法再次触发的bug,就是说提交一次后必须刷新才能再次提交,这就坑了~ 于是想办法解决它~ 在网上找了一些资料,找到这几种方 ...