题目链接: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. http.sys的简单应用

    //public void Run() //{ // //httpListener提供一个简单,可通过编程方式控制的Http协议侦听器.此类不能被继承. // if (!HttpListener.Is ...

  2. MyBatis批量添加和删除

    一.批量插入 二.批量删除

  3. iOS: 查看 UIView 的视图树

    在想要查看的 UIView 附近打个断点,运行,直到停在断点处,在控制台键入:po [view recursiveDescription],回车. (lldb) po [self recursiveD ...

  4. eclipse中去掉validate的方法

    昨天在右击项目想选择refresh的时候一不小心选择了validate,就发现target包出现了红色的叉号.当时觉得反正项目运行没有什么异常,就这么凑合了一天半多. 后来,当我改jsp的时候从< ...

  5. rsync:重要的安全参数

    ---------------------------------------------------------------------------------------------------- ...

  6. Spring MVC手札

    本文用于记录使用Spring MVC中的零散手札 1.在普通java类中获取HttpServletRequest对象  在web.xml的listener节点加入 <listener> & ...

  7. 线程与COM

    场景: C++部分封装为COM,C#来调用.调用可能是在线程中的. 应用程序退出时,C#的部分 自动清理,某些线程可能还没有完全停掉. COM内部的东西也在释放内存. 这个时候,稍有不慎,就会崩溃. ...

  8. RSS 使用前详解

    您应当具备的基础知识 在继续学习之前,您需要对下面的知识有基本的了解: HTML / XHTML XML / XML 命名空间 什么是 RSS? RSS 指 Really Simple Syndica ...

  9. centos7 安装keepalived

    node1 192.168.5.101 node2 192.168.5.102 1.安装 openssl openssl-devel yum install openssl openssl-devel ...

  10. MTK 隐藏上方的状态栏

    步骤一: 源码/frameworks/base/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.ja ...