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. js script中引用其他script

    在需要引用目标js中引用其他js依赖项 可以使用这个方法直接在js顶部加入这一行即可 document.write("<script type='text/javascript' sr ...

  2. windows下C++环境的配置

    方法一--VS: 使用windows开发神器visio studio.这种方法比较简单,直接下载一个最新的vs安装就行.不单单是C++,C.C#.VB等都可以开发. 方法二--只安装C++编译器: 最 ...

  3. 我的Git使用-资料查询,名博笔记

    1.首先您要知道什么是GIT 2.然后对其GIT的历史有所了解(吹牛b的时候用得着,如果还不知道 linux 脱袜子 Linus Torvalds  o(︶︿︶)o ) Git 常用资料查询站点. 官 ...

  4. Linux 安装node.js ---- 源码编译的方式

    一 : 普通用户: 安装前准备环境: 1.检查Linux 版本 命令: cat /etc/redhat-release 2.检查 gcc.gcc-c++ 是否安装过 命令: rpm -q gcc rp ...

  5. 阻塞非阻塞,同步异步四种I/O方式

    举一个去书店买书的例子吧: (同步)阻塞: 你去书店买书,到柜台告诉店员,需要买一本APUE,然后一直在柜台等.(阻塞) 店员拿到书以后交给你. (同步)非阻塞: 你去书店买书,到柜台告诉店员A,需要 ...

  6. MyISAM和InnoDB索引区别

    MyISAM引擎使用B+Tree作为索引结构,叶节点的data域存放的是数据记录的地址.下图是MyISAM索引的原理图: 图8 这里设表一共有三列,假设我们以Col1为主键,则图8是一个MyISAM表 ...

  7. 解决PKIX(PKIX path building failed) 问题 unable to find valid certification path to requested target

    最近在写java的一个服务,需要给远程服务器发送post请求,认证方式为Basic Authentication,在请求过程中出现了 PKIX path building failed: sun.se ...

  8. fool

    from PIL import Imageimg = Image.open("D:\\pic2\\CZA3302.png")(w,h) = img.sizeim=img.conve ...

  9. java UDP

    UDP 与 tcp 连接的 区别 以及  两者的不同 UDp 1 面向的是无连接的网络方式 2 传输速度快 (但是容易发生丢包 ) 3 传输的数据的大小带有的限制 一般是在64k  范围内 tcp 1 ...

  10. Spark中常用工具类Utils的简明介绍

    <深入理解Spark:核心思想与源码分析>一书前言的内容请看链接<深入理解SPARK:核心思想与源码分析>一书正式出版上市 <深入理解Spark:核心思想与源码分析> ...