Problem Description
As one of the most powerful brushes, zhx submits a lot of code on many oj and most of them got AC.

One day, zhx wants to count how many submissions he made on
n
ojs. He knows that on the ith
oj, he made ai
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.
 
Input
Multiply test cases(less than
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(lowercase).
The length of a number will not execeed 200.
 
Output
For each test case, output a single line indicating the answer in
B−base(no
leading zero).
 
Sample Input
2 3
2
2
1 4
233
3 16
ab
bc
cd
 
Sample Output
1
233
14
Problem Description
As one of the most powerful brushes, zhx submits a lot of code on many oj and most of them got AC.

One day, zhx wants to count how many submissions he made on
n
ojs. He knows that on the ith
oj, he made ai
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.
 
Input
Multiply test cases(less than
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(lowercase).
The length of a number will not execeed 200.
 
Output
For each test case, output a single line indicating the answer in
B−base(no
leading zero).
 
Sample Input
2 3
2
2
1 4
233
3 16
ab
bc
cd
 
Sample Output
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&#39;s submissions (进制转换)的更多相关文章

  1. HDU - 5186 - zhx&#39;s submissions (精密塔尔苏斯)

    zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  2. HDU 4937 Lucky Number (数学,进制转换)

    题目 参考自博客:http://blog.csdn.net/a601025382s/article/details/38517783 //string &replace(iterator fi ...

  3. HDU 2031 进制转换(10进制转R进制)

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=2031 进制转换 Time Limit: 2000/1000 MS (Java/Others)    M ...

  4. HDU 2097 Sky数 进制转换

    解题报告:这题就用一个进制转换的函数就可以了,不需要转换成相应的进制数,只要求出相应进制的数的各位的和就可以了. #include<cstdio> #include<string&g ...

  5. hdu 2031 进制转换(栈思想的使用)

    进制转换 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  6. HDU 1877 又一版 A+B(进制转换)

    看了http://lovnet.iteye.com/blog/1690276的答案 好巧妙的方法 递归实现十进制向m进制转换 #include "stdio.h" int m; v ...

  7. jstack:将Process Explorer中看到的进程ID做16进制转换,到ThreadDump中加上0x 前缀即能找到对应线程(转)

    原文链接:http://www.iteye.com/topic/1133941 症状: 使用Eclipse win 64位版本,indigo及kepler都重现了,使用tomcat 6.0.39,jd ...

  8. 进制转换,杭电0j-2031

    进制转换,杭电0j-2031原题地址:http://acm.hdu.edu.cn/showproblem.php?pid=2031 [Problem Description] 输入一个十进制数N,将它 ...

  9. <算法>进制转换超详细

    16转10 用竖式计算: 16进制数的第0位的权值为16的0次方,第1位的权值为16的1次方,第2位的权值为16的2次方 第0位: 5 * 16^0 = 5 第1位: F * 16^1 = 240 第 ...

随机推荐

  1. Fiddler2 中文手册

    原文:http://blog.sina.com.cn/s/blog_66a13b8f0100vgfi.html 最近一阵研究 Fiddler2 的使用来着,一开始看起来有点找不着北,索性就根据官网资料 ...

  2. JAVA 文本 TXT 操作工具类

    import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; imp ...

  3. easyui 后台页面,在Tab中的链接点击后添加一个新TAB的解决方法

    1.示例1 新增一个按钮 添加点击事件 onclick="self.parent.addTab('百度','http://www.baidu.com','icon-add')" 如 ...

  4. utf8_general_ci、utf8_unicode_ci和utf8_bin的区别

    utf8_general_ci 不区分大小写,这个你在注册用户名和邮箱的时候就要使用. utf8_general_cs 区分大小写,如果用户名和邮箱用这个就会照成不良后果. utf8_bin: com ...

  5. 第六章 consul UI

    1.建立三个consul节点(一个server+两个client) 具体的过程见http://www.cnblogs.com/java-zhao/p/5375132.html 1)在终端下启动vagr ...

  6. sbusurface scattering

    http://www.iryoku.com 感觉Jorge有这个世界的全部.... 2012年那篇  那年他刚博士毕业.... 抄了他很多东西 ....抄了他这么多年..... 言归正传 对sss我之 ...

  7. windows10 phantomjs 安装和使用

    1.下载phantomjs和 Casper phantomjs下载地址:http://phantomjs.org/download.html Casper下载地址:http://casperjs.or ...

  8. [AngularJS] Angular 1.3 ng-model-options - getterSetter

    getterSetter:  boolean value which determines whether or not to treat functions bound to ngModel as ...

  9. FileAlreadyExistsException: Output directory hdfs://ubuntu:9000/output09 already exists

    14/07/21 17:49:59 ERROR security.UserGroupInformation: PriviledgedActionException as:chenlongquan ca ...

  10. Project has no project.properties file! Edit the project properties to set one.

    解决办法: 右击项目,选择android tools-->fix project properties.然后重启eclipse即可.