HDU 5186 zhx's submissions (进制转换)
One day, zhx wants to count how many submissions he made on
n
ojs. He knows that on the i
oj, he made a
submissions. And what you should do is to add them up.
To make the problem more complex, zhx gives you n
B−base
numbers and you should also return a B−base
number to him.
What's more, zhx is so naive that he doesn't carry a number while adding. That means, his answer to
5+6
in 10−base
is 1
And he also asked you to calculate in his way.
1000
Seek EOF
as the end of the file.
For each test, there are two integers n
and B
separated by a space. (1≤n≤100
2≤B≤36
Then come n lines. In each line there is a B−base
number(may contain leading zeros). The digits are from
0
to 9
then from a
to z
The length of a number will not execeed 200.
B−base
leading zero).
2 3
2
2
1 4
233
3 16
ab
bc
cd
1
233
14
One day, zhx wants to count how many submissions he made on
n
ojs. He knows that on the i
oj, he made a
submissions. And what you should do is to add them up.
To make the problem more complex, zhx gives you n
B−base
numbers and you should also return a B−base
number to him.
What's more, zhx is so naive that he doesn't carry a number while adding. That means, his answer to
5+6
in 10−base
is 1
And he also asked you to calculate in his way.
1000
Seek EOF
as the end of the file.
For each test, there are two integers n
and B
separated by a space. (1≤n≤100
2≤B≤36
Then come n lines. In each line there is a B−base
number(may contain leading zeros). The digits are from
0
to 9
then from a
to z
The length of a number will not execeed 200.
B−base
leading zero).
2 3
2
2
1 4
233
3 16
ab
bc
cd
1
233
14
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map> #define L(x) (x<<1)
#define R(x) (x<<1|1)
#define MID(x,y) ((x+y)>>1) typedef __int64 ll; #define fre(i,a,b) for(i = a; i <b; i++)
#define mem(t, v) memset ((t) , v, sizeof(t))
#define sf(n) scanf("%d", &n)
#define sff(a,b) scanf("%d %d", &a, &b)
#define sfff(a,b,c) scanf("%d %d %d", &a, &b, &c)
#define pf printf
#define bug pf("Hi\n") using namespace std; #define INF 0x3f3f3f3f
#define N 1001 #define mod 1000000007 char a[300];
int ans[N]; int main()
{
int i,j,n,b;
int ma;
while(~sff(n,b))
{
mem(ans,0);
ma=0;
while(n--)
{
scanf("%s",a); int k=0;
int len=strlen(a);
ma=max(ma,len); for(i=len-1;i>=0;i--)
{
int te;
if(a[i]>='0'&&a[i]<='9') te=a[i]-'0';
else te=a[i]-'a'+10;
ans[k]=(ans[k]+te)%b;
k++;
} } int i=ma-1;
while(ans[i]==0&&i>=0) i--; if (i<0)pf("0"); // 坑爹的地方 for(;i>=0;i--)
if(ans[i]<10)
printf("%d",ans[i]);
else
printf("%c",ans[i]-10+'a'); printf("\n");
}
return 0; }
HDU 5186 zhx's submissions (进制转换)的更多相关文章
- HDU - 5186 - zhx's submissions (精密塔尔苏斯)
zhx's submissions Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others ...
- HDU 4937 Lucky Number (数学,进制转换)
题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator fi ...
- HDU 2031 进制转换(10进制转R进制)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2031 进制转换 Time Limit: 2000/1000 MS (Java/Others) M ...
- HDU 2097 Sky数 进制转换
解题报告:这题就用一个进制转换的函数就可以了,不需要转换成相应的进制数,只要求出相应进制的数的各位的和就可以了. #include<cstdio> #include<string&g ...
- hdu 2031 进制转换(栈思想的使用)
进制转换 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- HDU 1877 又一版 A+B(进制转换)
看了http://lovnet.iteye.com/blog/1690276的答案 好巧妙的方法 递归实现十进制向m进制转换 #include "stdio.h" int m; v ...
- jstack:将Process Explorer中看到的进程ID做16进制转换,到ThreadDump中加上0x 前缀即能找到对应线程(转)
原文链接:http://www.iteye.com/topic/1133941 症状: 使用Eclipse win 64位版本,indigo及kepler都重现了,使用tomcat 6.0.39,jd ...
- 进制转换,杭电0j-2031
进制转换,杭电0j-2031原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=2031 [Problem Description] 输入一个十进制数N,将它 ...
- <算法>进制转换超详细
16转10 用竖式计算: 16进制数的第0位的权值为16的0次方,第1位的权值为16的1次方,第2位的权值为16的2次方 第0位: 5 * 16^0 = 5 第1位: F * 16^1 = 240 第 ...
随机推荐
- gdb -Mysql源代码级调试方法
http://blog.csdn.net/hitzhang/article/details/5985474 gdb -q --batch --ex "set height 0" - ...
- Unity3d地图制作之模型高光
由于颇受暗黑破坏神美工的影响,最近都在研究怎么制作场景地图之类的. 那么今日讲的模型高光虽然和地图无关,但是也涉及到一些美工的知识,尤其是shader. 按照国际惯例,先贴一张图饱饱眼福. 大家可以看 ...
- faked 一个用于 mock 后端 API 的轻量工具
一.简介 faked 是一个在前端开发中用于 mock 服务端接口的模块,轻量简单,无需要在本地启动 Server 也无需其它更多的资源,仅在浏览器中完成「请求拉截」,配合完整的「路由系统」轻而易举的 ...
- sql 语句之 case
case语句语法: --简单Case函数 CASE sex WHEN '1' THEN '男' WHEN '2' THEN '女' ELSE '其他' END --Case搜索函数 CASE WHEN ...
- 如何判断linux使用的是HDD还是SSD、HHD;磁盘阵列RAID
硬盘种类:SSD固态硬盘.HDD机械硬盘.HHD混合硬盘(里面既有机械硬盘也有固态硬盘,固态硬盘用来高速缓存,机械硬盘用来存储). HHD是机械硬盘和固态硬盘的结合体.我们可以理解为其就是两块硬盘,固 ...
- 数学图形(1.20)N叶草
有N个叶子的草 相关软件参见:数学图形可视化工具,使用自己定义语法的脚本代码生成数学图形.该软件免费开源.QQ交流群: 367752815 vertices = t = to (*PI) r = n ...
- 数学图形(1.18)Poinsot's spiral螺线
它是一种螺线,其特点是细分时无限递归. 相关软件参见:数学图形可视化工具,使用自己定义语法的脚本代码生成数学图形.该软件免费开源.QQ交流群: 367752815 vertices = t = *PI ...
- go语言基础之字符串类型 和 字符与字符串类型的区别
1.字符串类型 示例1: package main //必须有一个main包 import "fmt" func main() { var str1 string str1 = & ...
- 创建带Mipmap的osg::Image
我们常用osgDB::readImage或者osg::Image::allocateImage()方式创建Image对象, 跟深一步的带Mipmap的Image怎样创建呢? 偶然在分析osgParti ...
- 如何从头开始确定虚拟SharePoint服务器场的配置(compute resource, network和storage)
让我们来设想一下, 假设你被上级要求设计一个SharePoint场, 用于满足自己公司的需求. 那么, 你会怎么做呢? 首先, 摆在你面前的是一系列的问题: 1. 用实体机搭建还是选用虚拟机平台? ...