http://acm.hdu.edu.cn/showproblem.php?pid=5186

题意是分别对每一位做b进制加法,但是不要进位

模拟,注意:1 去掉前置0 2 当结果为0时输出0,而不是全部去掉

#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn=101;
const int maxm=201;
int n,b;
char a[maxn][maxm];
int len[maxn];
char ans[maxm];
int getnum(char c){
if(c>='0'&&c<='9')return c-'0';
return c-'a'+10;
}
char getchar(int t){
if(t<10)return '0'+t;
return 'a'+t-10;
}
void add(int ind,int num){
int tmp=(getnum(ans[ind])+num)%b;
ans[ind]=getchar(tmp);
}
int main(){
while(scanf("%d%d",&n,&b)==2){
int mxlen=0;
for(int i=0;i<n;i++){
scanf("%s",a[i]);
len[i]=strlen(a[i]);
mxlen=max(mxlen,len[i]);
}
for(int i=0;i<mxlen;i++)ans[i]='0';
ans[mxlen]=0;
for(int j=1;j<=mxlen;j++){
for(int i=0;i<n;i++){
if(len[i]>=j){
add(mxlen-j,getnum(a[i][len[i]-j]));
}
}
}
int ind;
for(ind =0;ans[ind]=='0'&&ind<mxlen-1;ind++){}
printf("%s\n",ans+ind); }
return 0;
}

  

HDU 5186 zhx's submissions 模拟,细节 难度:1的更多相关文章

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

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

  2. HDU 5186 zhx&#39;s submissions (进制转换)

    Problem Description As one of the most powerful brushes, zhx submits a lot of code on many oj and mo ...

  3. hdu 5186(模拟)

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

  4. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  5. HDU 4782 Beautiful Soup (模拟+注意细节)

    思路就是用栈模拟,不用开实体的栈,直接记一个top指针就行. 说说这题的细节: 1.tag标签里的内容不要动,原样输出.比如<p aa bb cc>,就这样输出就行,不要删空格.题目中说了 ...

  6. HDU 5867 Water problem (模拟)

    Water problem 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5867 Description If the numbers ...

  7. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  8. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  9. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

随机推荐

  1. vue知识总汇

    学前预备知识 ECMAScript简介和ES6的新增语法 Nodejs基础 webpack的介绍 babel简介 vue基础 vue基础

  2. 9.python的列表

    list2 = [1, 2, 3, 4, 5, 6, 7 ]; print ("list2[1:5]: ", list2[1:5]) 得到 list2[1:5]:  [2, 3, ...

  3. Openstack(三)Haproxy+Keepalived双机

    3.1部署keepalived 3.1.1下载keepalived源码包,并解压 # wget http://www.keepalived.org/software/keepalived-1.4.2. ...

  4. 【译】Using Objects to Organize Your Code

    耗了一个晚上吐血翻译不过也学到了不少...<使用对象来组织你的代码>,翻译中发现原作者在原文中有部分代码有误或不全,本文已修改和添加~ 丽贝卡·墨菲原文链接:http://rmurphey ...

  5. AngularJS SQL

    服务端代码 以下列出了列出了几种服务端代码类型: 使用 PHP 和 MySQL.返回 JSON. 使用 PHP 和 MS Access.返回 JSON. 使用 ASP.NET, VB, 及 MS Ac ...

  6. 22. Generate Parentheses(回溯)

    Given n pairs of parentheses, write a function to generate all combinations of well-formed parenthes ...

  7. la5135 无向图 点-双连通 运用

    大白书 P314 #include <iostream> #include <algorithm> #include <string.h> #include < ...

  8. [one day one question] safari缓存太厉害

    问题描述: safari缓存太厉害,这怎么破? 解决方案: window.onpageshow = function(event) { if (event.persisted) { window.lo ...

  9. 隐藏Apche、Nginx、PHP的版本号提高网站安全性

    隐藏Apache版本号 在apache配置文件httpd.conf中,加入以下代码 ServerTokens Prod ServerSignature Off 隐藏Nginx版本号 在nginx的配置 ...

  10. Activiti工作流引擎简介

    Activiti工作流引擎简介 一.概述 Activiti是由Alfresco软件在2010年5月17日发布的业务流程管理(BPM)框架,它是覆盖了业务流程管理,工作流,服务协作等领域的一个开源,灵活 ...