hdu 5186(模拟)
2024-08-24 15:50:59
zhx's submissions
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2293 Accepted Submission(s): 641
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.
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.
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
2
2
1 4
233
3 16
ab
bc
cd
Sample Output
1
233
14
233
14
Source
题意:给出n个字符串,这些字符串都是b进制的,将这些字符串相加,但是我们得到的结果是不需要进位的,问最后得到的结果是多少??
例:
3 16
ab
bc
cd
ab+bc = 57
57+cd = 14
题解:我的方法是先把字符串全部记下来,然后翻转,依照这些字符串中最长的那个进行补 0 ,然后依次相加,有进位时就减掉进制,记得判断负数,是负数就要进行取模变成正的,最后得到结果串记得翻转回来。
#include <iostream>
#include <cstdio>
#include <string.h>
#include <queue>
#include <algorithm>
#include <math.h>
using namespace std;
typedef long long LL; int main(){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
char res[];
char str[][];
int len[];
int MAX=-;
for(int i=;i<n;i++){
scanf("%s",str[i]);
len[i] = strlen(str[i]);
reverse(str[i],str[i]+len[i]);
MAX = max(MAX,len[i]);
}
for(int i=;i<n;i++){
for(int j=len[i];j<MAX;j++){
str[i][j] = '';
}
if(i==){
for(int j=;j<MAX;j++){
res[j] = str[][j];
}
}
}
int a,b;
for(int i=;i<n;i++){
for(int j=;j<MAX;j++){
if(str[i][j]<=''&&str[i][j]>='') a = str[i][j]-'';
else a = str[i][j]-'a'+;
if(res[j]<=''&&res[j]>='') b = res[j]-'';
else b = res[j]-'a'+;
int c = ((a+b-m)%m+m)%m;
if(c>=&&c<=) res[j] = c+'';
else res[j] = c-+'a';
}
}
reverse(res,res+MAX);
bool flag = false;
for(int i=;i<MAX-;i++){
if(res[i]!=''){
flag = true;
}
if(flag){
printf("%c",res[i]);
}
}
printf("%c\n",res[MAX-]);
}
return ;
}
最新文章
- AVL树的平衡算法(JAVA实现)
- Restful.Data,现招募有为骚年,群号 338570336
- android 键盘遮挡 父布局上滚解决
- 转: Git远程操作详解 (阮一峰)
- FastMM 定位内存泄露的代码位置
- POI给Excel添加数字筛选
- iOS设计模式之策略模式
- 创建immutable类
- Running Central Admin on Multiple Servers within a Farm
- dataTable 禁止分页
- JVM原理
- kafka leader 服务器均衡。
- String 类的实现(5)String常用函数
- koa2+webSocket 聊天室
- Go 语言结构体
- 如何用php实现分页效果
- jQuery 实现文字不停闪烁效果
- 一篇文章让你了解Android各个版本的历程
- lua的性能优化
- Python装饰器举例分析