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. eclipse的项目和配置文件 .project .cproject .classpath .metadata

    eclipse CDT建立project后在project name对应的目录下面会生成.project和.cproject两个隐藏文件. eclipse  java建立project后在projec ...

  2. 腾讯PHP工程师面试题两份

    试题一: PHP开发工程师笔试试卷 姓名:__________ 一.PHP开发部分 1.合并两个数组有几种方式,试比较它们的异同 2.请写一个函数来检查用户提交的数据是否为整数(不区分数据类型,可以为 ...

  3. 利用AWR 查看SQL 执行计划

    在AWR中定位到问题SQL语句后想要了解该SQL statement的具体执行计划,于是就用AWR报告中得到的SQL ID去V$SQL等几个动态性能视图中查询,但发现V$SQL或V$SQL_PLAN视 ...

  4. Visual Studio 2013在线文档地址备案

    Visual Studio 2013还没有离线的帮助文档,这里做个记录,以备后面使用. 地址:http://msdn.microsoft.com/zh-cn/library/dd831853.aspx

  5. mmap函数使用

    UNIX网络编程第二卷进程间通信对mmap函数进行了说明.该函数主要用途有三个:1.将一个普通文件映射到内存中,通常在需要对文件进行频繁读写时使用,这样用内存读写取代I/O读写,以获得较高的性能:2. ...

  6. 仿LOL项目开发第二天

    仿LOL项目开发第二天 by草帽 接着上节来讲,上节更新还没开始写代码逻辑,今天我们补充完整. 我们找到VersionManager脚本里面的CheckVersion方法: 首先我们想到检测版本,需要 ...

  7. 高性能HTML

    避免使用Iframe Iframe也叫内联frame,可以把一个HTML文档嵌入到另一个文档中.使用iframe的好处是被嵌入的文档可以完全独立于其父文档,凭借此特点我们通常可以使浏览器模拟多线程,需 ...

  8. input type=file文件选择表单元素二三事

    一.原生input上传与表单form元素 如果想使用浏览器原生特性实现文件上传(如图片)效果,父级的form元素有个东西不能丢,就是: enctype="multipart/form-dat ...

  9. 【python】列出http://www.cnblogs.com/xiandedanteng中所有博文的标题

    代码: # 列出http://www.cnblogs.com/xiandedanteng中所有博文的标题 from bs4 import BeautifulSoup import requests u ...

  10. uva:10487 - Closest Sums(二分查找)

    题目:10487 - Closest Sums 题目大意:给出一组数据,再给出m个查询的数字. 要求找到这组数据里的两个数据相加的和最靠近这个查询的数据,输出那两个数据的和. 解题思路:二分查找.这样 ...