HDU 5186 zhx's submissions (进制转换)

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
nHDU 5186 zhx's submissions (进制转换)
ojs. He knows that on the iHDU 5186 zhx's submissions (进制转换)thHDU 5186 zhx's submissions (进制转换)HDU 5186 zhx's submissions (进制转换)
oj, he made aHDU 5186 zhx's submissions (进制转换)iHDU 5186 zhx's submissions (进制转换)HDU 5186 zhx's submissions (进制转换)
submissions. And what you should do is to add them up.

To make the problem more complex, zhx gives you nHDU 5186 zhx's submissions (进制转换)
B−baseHDU 5186 zhx's submissions (进制转换)
numbers and you should also return a B−baseHDU 5186 zhx's submissions (进制转换)
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+6HDU 5186 zhx's submissions (进制转换)
in 10−baseHDU 5186 zhx's submissions (进制转换)
is 1HDU 5186 zhx's submissions (进制转换).
And he also asked you to calculate in his way.
 
Input
Multiply test cases(less than
1000HDU 5186 zhx's submissions (进制转换)).
Seek EOFHDU 5186 zhx's submissions (进制转换)
as the end of the file.

For each test, there are two integers nHDU 5186 zhx's submissions (进制转换)
and BHDU 5186 zhx's submissions (进制转换)
separated by a space. (1≤n≤100HDU 5186 zhx's submissions (进制转换),
2≤B≤36HDU 5186 zhx's submissions (进制转换))

Then come n lines. In each line there is a B−baseHDU 5186 zhx's submissions (进制转换)
number(may contain leading zeros). The digits are from
0HDU 5186 zhx's submissions (进制转换)
to 9HDU 5186 zhx's submissions (进制转换)
then from aHDU 5186 zhx's submissions (进制转换)
to zHDU 5186 zhx's submissions (进制转换)(lowercase).
The length of a number will not execeed 200.
 
Output
For each test case, output a single line indicating the answer in
B−baseHDU 5186 zhx's submissions (进制转换)(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
nHDU 5186 zhx's submissions (进制转换)
ojs. He knows that on the iHDU 5186 zhx's submissions (进制转换)thHDU 5186 zhx's submissions (进制转换)HDU 5186 zhx's submissions (进制转换)
oj, he made aHDU 5186 zhx's submissions (进制转换)iHDU 5186 zhx's submissions (进制转换)HDU 5186 zhx's submissions (进制转换)
submissions. And what you should do is to add them up.

To make the problem more complex, zhx gives you nHDU 5186 zhx's submissions (进制转换)
B−baseHDU 5186 zhx's submissions (进制转换)
numbers and you should also return a B−baseHDU 5186 zhx's submissions (进制转换)
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+6HDU 5186 zhx's submissions (进制转换)
in 10−baseHDU 5186 zhx's submissions (进制转换)
is 1HDU 5186 zhx's submissions (进制转换).
And he also asked you to calculate in his way.
 
Input
Multiply test cases(less than
1000HDU 5186 zhx's submissions (进制转换)).
Seek EOFHDU 5186 zhx's submissions (进制转换)
as the end of the file.

For each test, there are two integers nHDU 5186 zhx's submissions (进制转换)
and BHDU 5186 zhx's submissions (进制转换)
separated by a space. (1≤n≤100HDU 5186 zhx's submissions (进制转换),
2≤B≤36HDU 5186 zhx's submissions (进制转换))

Then come n lines. In each line there is a B−baseHDU 5186 zhx's submissions (进制转换)
number(may contain leading zeros). The digits are from
0HDU 5186 zhx's submissions (进制转换)
to 9HDU 5186 zhx's submissions (进制转换)
then from aHDU 5186 zhx's submissions (进制转换)
to zHDU 5186 zhx's submissions (进制转换)(lowercase).
The length of a number will not execeed 200.
 
Output
For each test case, output a single line indicating the answer in
B−baseHDU 5186 zhx's submissions (进制转换)(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; }
上一篇:docker-images(镜像)


下一篇:Java 泛型 中 super 怎么 理解?与 < ? extends T>有何不同?