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 第 ...
随机推荐
- localhost与127.0.0.1的区别 2
localhost与127.0.0.1的区别localhost与127.0.0.1的区别是什么?相信有人会说是本地ip,曾有人说,用127.0.0.1比localhost好,可以减少一次解析.看来这个 ...
- Linux使用jstat命令查看jvm的GC情况(转)
B. jstack jstack主要用来查看某个Java进程内的线程堆栈信息.语法格式如下: 1 jstack [option] pid 2 jstack [option] executable co ...
- osgi实战学习之路:2. maven+maven-bundle-plugin+karaf搭建osgi之HelloWorld
环境准备: jdk版本号 jdk:1.7 karaf: 版本号:apache-karaf-3.0.1 下载地址: http://pan.baidu.com/s/1qWM4Y1u http://kara ...
- git hub的GUI软件配置与使用
1. 安装两个软件 1. git的命令行程序--git for windows:http://git-scm.com/download/win 2. git的GUI程序--tortoisegit:ht ...
- 《Objective-C开发经典教程》
<Objective-C开发经典教程> 基本信息 原书名:Beginning Objective-C 原出版社: Apress 作者: (美)James Dovey Ash Furr ...
- MVC4 过滤器(转)
先来看看一个例子演示过滤器有什么用: public class AdminController : Controller { // ... instance variables and constru ...
- @ERR Unsupported CONFIG parameter: notify-keyspace-events
Caused by: redis.clients.jedis.exceptions.JedisDataException: ERR Unsupported CONFIG parameter: noti ...
- MIME简介
MIME(Multipurpose Internet Mail Extensions)多用途互联网邮件扩展类型.是设定某种扩展名的文件用一种应用程序来打开的方式类型,当该扩展名文件被访问的时候,浏览器 ...
- [置顶] 自娱自乐1之Linux UDC驱动(形式模板)
首先,我不是做驱动的开发人员.所以只能用自娱自乐来表示我的行为. 我不知道udc和gadget驱动是不是冷门的驱动,资料真是不多.我之前买了一本书,上面说到这些,就教你如何调试已写好的驱动.这样也可以 ...
- 使用IntelliJ IDEA开发Spring MVC HelloWorld
https://blog.csdn.net/industriously/article/details/52851588 https://blog.csdn.net/slow_wakler/artic ...