题目链接:http://ac.jobdu.com/problem.php?pid=1016

详解链接:https://github.com/zpfbuaa/JobduInCPlusPlus

参考代码:

//
// 1016 火星A+B.cpp
// Jobdu
//
// Created by PengFei_Zheng on 28/04/2017.
// Copyright © 2017 PengFei_Zheng. All rights reserved.
// #include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <cmath>
#define MAX_PRIME 30
#define MAX_SIZE 26
//#define debug using namespace std; int prime[MAX_PRIME]; bool isPrime(int x){
if(x<=) return false;
if(x==) return true;
int tmp = sqrt(x)+;
for(int i = ; i <= tmp ; i++){
if(x%i==)
return false;
}
return true;
} void calPrime(){
int num = ;
for(int i = ; num< ; i++){
if(isPrime(i)){
num++;
prime[num] = i;
}
}
} int a[MAX_SIZE];
int b[MAX_SIZE];
int sum[MAX_SIZE];
char c;
int lena, lenb, i, j; void init(){
memset(a, , sizeof(a));
memset(b, , sizeof(b));
memset(sum, , sizeof(sum));
c=' ';
lena=lenb=i=j=;
}
int main(){
calPrime();
#ifdef debug
for(int i = ; i < MAX_PRIME ; i++){
cout<<i<<" is : "<<prime[i]<<endl;
}
#endif
// freopen("/Users/pengfei_zheng/Desktop/input.txt", "r", stdin);
while(){
init();
char c; for(i = ; i < MAX_SIZE ; i++){
scanf("%d",&a[i]);
scanf("%c",&c);
if(c==' ')break;
}
lena = i;
for(j = ; j < MAX_SIZE ; j++){
scanf("%d",&b[j]);
scanf("%c",&c);
if(c=='\n')break;
}
lenb = j;
if(a[]== && b[]==)
break; int maxLen = lena>=lenb ? lena : lenb; int carry=;
int len = maxLen;
int x,y;
for(i = ; i <= maxLen; i++){
if(lena>=) x=a[lena--];
else x=;
if(lenb>=) y=b[lenb--];
else y=;
sum[len--]=(x+y+carry)%prime[i];
carry=(x+y+carry)/prime[i];
}
if(carry!=){
printf("%d,",carry);
}
for(i = ; i < maxLen ; i++){
printf("%d,",sum[i]);
}
printf("%d\n",sum[maxLen]);
}
return ;
}
/**************************************************************
Problem: 1016
User: zpfbuaa
Language: C++
Result: Accepted
Time:10 ms
Memory:1532 kb
****************************************************************/

题目1016:火星A+B(进制新问题)的更多相关文章

  1. PAT 1015 Reversible Primes (20分) 谜一般的题目,不就是个进制转换+素数判断

    题目 A reversible prime in any number system is a prime whose "reverse" in that number syste ...

  2. 九度OJ题目1080:进制转换(java)使用BigInteger进行进制转换

    题目描述: 将M进制的数X转换为N进制的数输出. 输入: 输入的第一行包括两个整数:M和N(2<=M,N<=36). 下面的一行输入一个数X,X是M进制的数,现在要求你将M进制的数X转换成 ...

  3. 九度oj 题目1080:进制转换

    题目描述: 将M进制的数X转换为N进制的数输出. 输入: 输入的第一行包括两个整数:M和N(2<=M,N<=36). 下面的一行输入一个数X,X是M进制的数,现在要求你将M进制的数X转换成 ...

  4. 【九度OJ】题目1080:进制转换 解题报告

    [九度OJ]题目1080:进制转换 解题报告 标签(空格分隔): 九度OJ 原题地址:http://ac.jobdu.com/problem.php?pid=1080 题目描述: 将M进制的数X转换为 ...

  5. 九度OJ 1340:小A的计算器 (进制转换)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:735 解决:202 题目描述: 以往的操作系统内部的数据表示都是二进制方式,小A新写了一个操作系统,系统内部的数据表示为26进制,其中0-2 ...

  6. PAT甲级——1100 Mars Numbers (字符串操作、进制转换)

    本文同步发布在CSDN:https://blog.csdn.net/weixin_44385565/article/details/90678474 1100 Mars Numbers (20 分) ...

  7. - >code vs 1475 m进制转十进制

    1475 m进制转十进制  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 白银 Silver 题解  查看运行结果   题目描述 Description 将m进制数n转化成一个 ...

  8. wikioi 1475 m进制转十进制

    /*===================================== 1475 m进制转十进制 题目描述 Description 将m进制数n转化成一个十进制数 m<=16 题目保证转 ...

  9. NYOJ-244 16进制的简单运算 AC 分类: NYOJ 2014-01-17 21:11 195人阅读 评论(0) 收藏

    #include<stdio.h> int main() { long x,y; char op; int t; scanf("%d ", &t); while ...

随机推荐

  1. Bulestacks模拟器Bulestacks.prop文件里中英文对照表

    打开“Bulestacks.prop”文件后可以看到以下内容,根据中英文对照表来修改即可. # begin build properties (开始设置系统性能)# autogenerated by ...

  2. yield 举例

    示例代码: 神奇的地方在于yield返回的是一个IEumerable,可以直接枚举. // yield-example.cs using System; using System.Collection ...

  3. 虚拟机中安装linux系统步骤

    参考:http://blog.csdn.net/u013111221/article/details/50856934 后面参考:http://blog.csdn.net/chenweitang123 ...

  4. JSP转发和重定向的区别

    重定向: response.sendRedirect("地址");         a. 页面地址显示最终页面         b. 不可向后传递参数         c. 跳到外 ...

  5. 安装程序配置服务器失败。参考服务器错误日志和C:\windows\sqlstp.log 了解更多信息

    重装sql经常遇到2个问题 1,以前的某个程序安装已在安装计算机上创建挂起的文件操作.运行安装程序之前必须重新启动计算机. 删除C:\Program Files\Microsoft SQL Serve ...

  6. Tree Recovery(前序中序求后序)

    Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14640   Accepted: 9091 De ...

  7. C#客户端嵌入Chrome浏览器的实现

    https://blog.csdn.net/lanwilliam/article/details/79639823 客户端软件,也就是传统的Winform软件,在很多时候是很好用的.因为在做一些打印. ...

  8. js循环异常

    1.当在循环数组时,数组发生变化,循环item 为定义undifined $.each(blogMng.commonKit.upLoadMng.medias, function (index, ite ...

  9. CentOS 6.4 命令行 安装 VMware Tools

    新建cdrom挂载目录 mkdir /mnt/cdrom 挂载光驱 mount -t auto /dev/cdrom /mnt/cdrom这命令就是把CentOS CDROM挂载在/mnt/cdrom ...

  10. photoshop制作简单ico图标

    新建16 * 16透明画布 字体20px 半径4px