hdu5186 zhx's submissions

4 篇文章 0 订阅
Izhx's submissions
Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64

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 $i^{th}$ oj, he made $a_i$ 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 \leq n \leq 100$, $2 \leq B \leq 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
该题是大数加法的模拟题, 最主要的wa点是在那个0 输入0 是输出0~~
#include<stdio.h>
#include<string.h>
int main()
{
	int n,m,k,maxl,flag,t,i,j;
	char a[300][300];
	int s[300];
	while(~scanf("%d%d",&n,&m))
	{
		memset(s,0,sizeof(s));
		maxl=flag=t=0;
		for(i=0;i<n;i++)
		{
			scanf("%s",a[i]);
		}
		
		for(i=0;i<n;i++)
		{	
			k=0;
			int l=strlen(a[i]);
			if(l>maxl)  maxl=l;
			for(j=l-1;j>=0;j--)  //k变量控制0 的输入和输出 
			{
				if(a[i][j]>='0'&&a[i][j]<='9')
				{
					s[k]+=a[i][j]-'0';
					s[k]%=m;
				}
				else if(a[i][j]>='a'&&a[i][j]<='z')
				{
					s[k]+=a[i][j]+10-'a';
					s[k]%=m;
				}
				k++;
			}	
		}
		for(i=maxl-1;i>=0;i--)  //输出 
		{
			if(s[i]==0&&flag==0)
			{
				t++;
			}
			else
			{
				flag=1;
				if(s[i]>=0&&s[i]<=9)
				printf("%d",s[i]);
				else printf("%c",s[i]-10+'a');
			} 
		}
		if(t==maxl)  printf("0\n");  //输入0  输出0 
		else printf("\n");
	}
	return 0;
} 



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值