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

hdu 5186(模拟)的更多相关文章

  1. HDU 5186 zhx's submissions 模拟,细节 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=5186 题意是分别对每一位做b进制加法,但是不要进位 模拟,注意:1 去掉前置0 2 当结果为0时输出0,而不是全 ...

  2. hdu 4891 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...

  3. hdu 5012 模拟+bfs

    http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...

  4. hdu 4669 模拟

    思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...

  5. 2013杭州网络赛C题HDU 4640(模拟)

    The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  6. HDU - 5186 - zhx&#39;s submissions (精密塔尔苏斯)

    zhx's submissions Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  7. HDU/5499/模拟

    题目链接 模拟题,直接看代码. £:分数的计算方法,要用double; #include <set> #include <map> #include <cmath> ...

  8. hdu 5003 模拟水题

    http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...

  9. hdu 5033 模拟+单调优化

    http://acm.hdu.edu.cn/showproblem.php?pid=5033 平面上有n个建筑,每个建筑由(xi,hi)表示,m组询问在某一个点能看到天空的视角范围大小. 维护一个凸包 ...

随机推荐

  1. Internet History,Technology and Security

    Internet History,Technology and Security(简单记录) First Week High Stakes Research in Computing,and Comm ...

  2. Eclipse下JRebel6.5.0热部署插件安装、破解及配置

    发现一个问题:如果安装了jRebel,但是并未对项目添加jRebel监听时,如果重写jar包中的类, 虽然重写后的类会得到编译(classes中的class已经是修改后的class),但是并不会调用重 ...

  3. TCP的挥手协议和握手协议2

    三次握手协议:三次握手协议的主要过程是交互彼此之间的初始序列号,如果没有确认的ACK帧可以么?肯定是可以的 client A -------> server B client A 发送了自己的初 ...

  4. [C/C++] extern关键字详解以及与static、const区别

    extern用法详解: 1. 声明外部实体 声明外部全局变量或对象,一般用于头文件中,表示在其它编译单元内定义的变量,链接时进行外部链接,如: extern int ivalue; 此时的extern ...

  5. sqoop工具从oracle导入数据2

    sqoop工具从oracle导入数据 sqoop工具是hadoop下连接关系型数据库和Hadoop的桥梁,支持关系型数据库和hive.hdfs,hbase之间数据的相互导入,可以使用全表导入和增量导入 ...

  6. java8 增强的Iterator遍历集合元素

    Iterator接口也是Java集合框架的成员,与Collection和Map两个系列的集合不一样的是Collection和Map系列主要用于充当容器的作用,而Iterator正如其名字一样是主要用于 ...

  7. [洛谷P2384]最短路

    题目大意:给你一个图,要你求出其中1->n路径中乘积最小的一条路 题解:用$log_2$把乘法变成加法,然后记录每个点的前驱,最后求出答案 C++ Code: #include<cstdi ...

  8. 2018牛客多校第一场 B.Symmetric Matrix

    题意: 构造一个n*n的矩阵,使得Ai,i = 0,Ai,j = Aj,i,Ai,1+Ai,2+...+Ai,n = 2.求种类数. 题解: 把构造的矩阵当成邻接矩阵考虑. 那么所有点的度数都为2,且 ...

  9. MFC 相关类、函数

    timeSetEvent()函数 CRectTracker类的使用 SetLocalTime设置本地时间 AdjustTokenPrivileges启用权限

  10. [Leetcode] add binary 二进制加法

    Given two binary strings, return their sum (also a binary string). For example,a ="11"b =& ...