又一版 A+B

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 15345    Accepted Submission(s): 5868

Problem Description
输入两个不超过整型定义的非负10进制整数A和B(<=231-1),输出A+B的m (1 < m <10)进制数。






 
Input
输入格式:测试输入包含若干测试用例。每个测试用例占一行,给出m和A,B的值。

当m为0时输入结束。
 
Output
输出格式:每个测试用例的输出占一行,输出A+B的m进制数。
 
Sample Input
8 1300 48
2 1 7
0
 
Sample Output
2504
1000
 
Author
ZJU
 
Source

有一个比较坑的地方,如果A,B都是零是需要输出0的,需要加一步特判

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<algorithm>
using namespace std;
int a[100000];
int main()
{
__int64 m,A,B;
while(cin>>m)
{
if(m==0) break;
memset(a,0,sizeof(a));
cin>>A>>B;
if(A==0&&B==0)
{
printf("0\n");
continue;
}
__int64 ans=A+B;
int cnt=0;
while(ans)
{
a[cnt++]=ans%m;
ans/=m;
}
for(int i=cnt-1;i>=0;i--)
printf("%d",a[i]);
printf("\n");
}
return 0;
}

 

hdoj--1877--又一版 A+B(水题)的更多相关文章

  1. HDU 2083 简易版之最短距离 --- 水题

    HDU 2083 简易版之最短距离 /* HDU 2083 简易版之最短距离 */ #include <cstdio> #include <algorithm> using n ...

  2. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  3. 水题 HDOJ 4727 The Number Off of FFF

    题目传送门 /* 水题:判断前后的差值是否为1,b[i]记录差值,若没有找到,则是第一个出错 */ #include <cstdio> #include <iostream> ...

  4. 水题 HDOJ 4716 A Computer Graphics Problem

    题目传送门 /* 水题:看见x是十的倍数就简单了 */ #include <cstdio> #include <iostream> #include <algorithm ...

  5. HDOJ/HDU 1328 IBM Minus One(水题一个,试试手)

    Problem Description You may have heard of the book '2001 - A Space Odyssey' by Arthur C. Clarke, or ...

  6. HDOJ/HDU 1256 画8(绞下思维~水题)

    Problem Description 谁画8画的好,画的快,今后就发的快,学业发达,事业发达,祝大家发,发,发. Input 输入的第一行为一个整数N,表示后面有N组数据. 每组数据中有一个字符和一 ...

  7. HDOJ/HDU 2560 Buildings(嗯~水题)

    Problem Description We divide the HZNU Campus into N*M grids. As you can see from the picture below, ...

  8. HDOJ(HDU) 2090 算菜价(简单水题、)

    Problem Description 妈妈每天都要出去买菜,但是回来后,兜里的钱也懒得数一数,到底花了多少钱真是一笔糊涂帐.现在好了,作为好儿子(女儿)的你可以给她用程序算一下了,呵呵. Input ...

  9. HDOJ(HDU) 1859 最小长方形(水题、、)

    Problem Description 给定一系列2维平面点的坐标(x, y),其中x和y均为整数,要求用一个最小的长方形框将所有点框在内.长方形框的边分别平行于x和y坐标轴,点落在边上也算是被框在内 ...

  10. HDOJ(HDU) 1555 How many days?(水题)

    Problem Description 8600的手机每天消费1元,每消费K元就可以获赠1元,一开始8600有M元,问最多可以用多少天? Input 输入包括多个测试实例.每个测试实例包括2个整数M, ...

随机推荐

  1. NOI模拟赛(3.8)Problem B

    Description Alice和Bob在玩一个游戏,给出一张n*m的棋盘,上面有一些点是障碍,游戏的开始,Alice选定棋盘上任意一个不是障碍的格子,并且将一枚棋子放在其中,然后Bob先手,两人轮 ...

  2. allegro中原理图和pcb中元件的交互

    一.前言: 所谓的交互是这样的,在原理图里点击某个元件,在pcb图中就相应的被选中,这样在元器件刚导进pcb中布局放置元器件的时候可以为我们提供很大的方便. 二.前提: pcb中导入元件是这种方式: ...

  3. 【转】Asp.net MVC Comet推送

    原文链接:http://www.cnblogs.com/kissdodog/p/4283485.html 一.简介 在Asp.net MVC实现的Comet推送的原理很简单. 服务器端:接收到服务器发 ...

  4. java生成6位随机数字

    //生成6位随机数字 System.out.println((int)((Math.random()*9+1)*100000)); //生成5位随机数字 System.out.println((int ...

  5. python pip 安装一些包找不到的问题 Could not find a version that satisfies....

    有时我们使用下载python 自带的pip 安装一些工具包时,会报如下错误 找不到满意的版本,这时就是我们的pip可能需要升级了,所以使用 python -m pip install --upgrad ...

  6. BNUOJ 2105 Distance Queries

    Distance Queries Time Limit: 2000ms Memory Limit: 30000KB This problem will be judged on PKU. Origin ...

  7. [luoguP2827] 蚯蚓(堆?队列!)

    传送门 35分做法 用堆来取最大值,暴力更新其余数的值. 65~85分做法 还是用堆来取最大值,其余的数增加可以变成新切开的两个数减少,最后统一加上一个数. #include <queue> ...

  8. 【KMP+最小循环节】F. Cyclic Nacklace

    https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/F [题意] 给定一个字符串,问在字符串后最少添加多少个字母,得到的新字符串能是前 ...

  9. hdu - 3549 Flow Problem (最大流模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=3549 Ford-Fulkerson算法. #include <iostream> #include ...

  10. Parent and son

    Give you a tree with N vertices and N‐ 1 edges, and then ask you Q queries on “which vertex is Y's s ...