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.
 
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
 
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 ;
}

最新文章

  1. AVL树的平衡算法(JAVA实现)
  2. Restful.Data,现招募有为骚年,群号 338570336
  3. android 键盘遮挡 父布局上滚解决
  4. 转: Git远程操作详解 (阮一峰)
  5. FastMM 定位内存泄露的代码位置
  6. POI给Excel添加数字筛选
  7. iOS设计模式之策略模式
  8. 创建immutable类
  9. Running Central Admin on Multiple Servers within a Farm
  10. dataTable 禁止分页
  11. JVM原理
  12. kafka leader 服务器均衡。
  13. String 类的实现(5)String常用函数
  14. koa2+webSocket 聊天室
  15. Go 语言结构体
  16. 如何用php实现分页效果
  17. jQuery 实现文字不停闪烁效果
  18. 一篇文章让你了解Android各个版本的历程
  19. lua的性能优化
  20. Python装饰器举例分析

热门文章

  1. 【WebService】——阶段小结
  2. 【SSH】——spring的控制反转和依赖注入
  3. IE浏览器报Promise未定义的错误
  4. JS frame 跨域 传值
  5. XJOI NOIP模拟题2
  6. poj 2226 Muddy Fields (二分匹配)
  7. P3375【模板】KMP字符串匹配
  8. IHE PIX规范
  9. 获取Parameter参数值,方便调试使用
  10. 版本7以上IE以文件夹视图方式打开FTP的解决