BestCoder Round #33 1001 zhx's submissions
来源:互联网 发布:64位软件 编辑:程序博客网 时间:2024/05/20 13:07
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5186
题意:对给定n个b进制的数求和。但是题目要求在计算和时,如需进位的地方均不进位。
思路: 按照题目要求直接模拟,类似大数加法。对每位的和直接对b取余。特别注意 最后的结果不能输出前导0。
代码如下:
#include <iostream>#include <iomanip>#include <cstdio>#include <algorithm>#include <cmath>#include <queue>#include <vector>#include <stack>#include <string>#include <cstring>#include <cassert>using namespace std;typedef long long ll;const int maxn=2222;const int INF=0x7fffffff;const int mod=1e7+7;#define LSON l,m,rt<<1#define RSON m+1,r,rt<<1|1#define ESP 1e-7int n,b;char a[111][222];int get_al(char s) { return s-'a'+10;}int get_num(char s) { return s-'0';}char give_al(int z) { if(z<10) return z+'0'; else return z-10+'a';}char *add(char s1[], char s2[]) { int x=(int)strlen(s1), y=(int)strlen(s2); int k=max(x, y); s1[k--]='\0'; x--,y--; while(x>=0 && y>=0) { int p,q; if(s1[x]>='0' && s1[x]<='9') p=get_num(s1[x]); else p=get_al(s1[x]); if(s2[y]>='0' && s2[y]<='9') q=get_num(s2[y]); else q=get_al(s2[y]); s1[k--]=give_al((p+q)%b); x--,y--; } while(x>=0) s1[k--]=s1[x--]; while(y>=0) s1[k--]=s2[y--]; return s1;}void sum() { for(int i=1;i<n;i++) add(a[0], a[i]); bool tag=false;//判断是否可以输出,避免输出前导0 int len=(int)strlen(a[0]); for(int i=0;i<len-1;i++) { if(a[0][i]!='0') tag=true; if(tag) printf("%c", a[0][i]); } printf("%c\n", a[0][len-1]);}int main() { while(scanf("%d%d", &n, &b)!=EOF) { getchar(); for(int i=0;i<n;i++) scanf("%s", a[i]); sum(); } return 0;}
0 0
- BestCoder Round #33 1001 zhx's submissions
- BestCoder #33 zhx's submissions
- BestCoder Round #33(zhx's submissions-手速题,注意判断00和0的情况)
- BestCoder Round #33 1002 zhx's contest
- hdu5186 zhx's submissions
- BestCoder Round #33(zhx's contest-快速乘法)
- hdu 5186 zhx's submissions
- HDU - 5186 zhx's submissions
- hdu 5186 zhx's submissions
- zhx's contest BestCoder Round #33(快速乘法+快速幂的原理)
- hdu 5186 zhx's submissions(模拟)
- hdu 5188 zhx and contest && BestCoder Round #33
- 【CUGBACM15级BC第33场 A】hdu 5186 zhx's submissions
- HDU 5186 zhx's submissions (进制转换)
- HDU - 5186 - zhx's submissions (大数高精度)
- HDU 5186 zhx's submissions 模拟水题
- HDU-5186-zhx's submissions(Java+简单模拟)
- 杭电 HDU ACM 5186 zhx's submissions
- jfware开始篇: hibernate4.1.9 + spring 3.2.2整合示例(CRUD)
- iOS- 利用AFNetworking(AFN) - 实现文件断点下载
- iOS应用性能调优的25个建议和技巧
- QT开发之旅四邮件发送工具
- 使用 CAS 在 Tomcat 中实现单点登录
- BestCoder Round #33 1001 zhx's submissions
- oracle序列详解
- PLSQL常用配置列表
- SQL的inner join、left join、right join、full outer join、union、union all的区别
- python 计算运算时间
- 每日一佳——SVM Optimization: Inverse Dependence on Training Set Size(Shai Shalev-Shwartz et al,ICML,2008)
- weblogic域管理员密码的修改后,服务不能启动了,这样办?
- jQuery DataTables插件 aoColumnDefs跟aoColumns的用法
- COM技术