HDU 5186 zhx's submissions 模拟水题
2015-03-15 10:30
302 查看
题意就是给n个b进制的数,求它们相加的和,有一个条件就是相加不进位,输出结果为没有前导0.
(原来有中文题的。只能说英文太渣没有看到输出结果没有前导0这个条件。)
代码:
//author: CHC
//First Edit Time: 2015-03-14 19:09
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const int MAXN=1e+4;
const int MAXM=1e+5;
const int INF = numeric_limits<int>::max();
const LL LL_INF= numeric_limits<LL>::max();
int getnums(char ch){
if(ch>='0'&&ch<='9')return ch-'0';
else return 10+ch-'a';
}
char getchar(int num){
if(num>=0&&num<=9)return num+'0';
else return num-10+'a';
}
char strs[200][300];
char tmp[300];
char ans[300];
int main()
{
int n,k;
while(~scanf("%d%d",&n,&k)){
memset(strs,0,sizeof(strs));
for(int i=0;i<n;i++){
scanf("%s",tmp);
for(int j=strlen(tmp)-1,k=0;j>=0;j--,k++){
strs[i][k]=tmp[j];
}
}
memset(ans,'0',sizeof(ans));
int m_len=0;
for(int i=0;i<n;i++){
int len=strlen(strs[i]);
m_len=max(len,m_len);
for(int j=0;j<len;j++){
ans[j]=getchar((getnums(ans[j])+getnums(strs[i][j]))%k);
}
}
int flag=m_len;
for(;flag>0&&ans[flag]=='0';flag--);
for(int i=flag;i>=0;i--)putchar(ans[i]);
puts("");
}
return 0;
}
(原来有中文题的。只能说英文太渣没有看到输出结果没有前导0这个条件。)
代码:
//author: CHC
//First Edit Time: 2015-03-14 19:09
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <limits>
using namespace std;
typedef long long LL;
const int MAXN=1e+4;
const int MAXM=1e+5;
const int INF = numeric_limits<int>::max();
const LL LL_INF= numeric_limits<LL>::max();
int getnums(char ch){
if(ch>='0'&&ch<='9')return ch-'0';
else return 10+ch-'a';
}
char getchar(int num){
if(num>=0&&num<=9)return num+'0';
else return num-10+'a';
}
char strs[200][300];
char tmp[300];
char ans[300];
int main()
{
int n,k;
while(~scanf("%d%d",&n,&k)){
memset(strs,0,sizeof(strs));
for(int i=0;i<n;i++){
scanf("%s",tmp);
for(int j=strlen(tmp)-1,k=0;j>=0;j--,k++){
strs[i][k]=tmp[j];
}
}
memset(ans,'0',sizeof(ans));
int m_len=0;
for(int i=0;i<n;i++){
int len=strlen(strs[i]);
m_len=max(len,m_len);
for(int j=0;j<len;j++){
ans[j]=getchar((getnums(ans[j])+getnums(strs[i][j]))%k);
}
}
int flag=m_len;
for(;flag>0&&ans[flag]=='0';flag--);
for(int i=flag;i>=0;i--)putchar(ans[i]);
puts("");
}
return 0;
}
相关文章推荐
- HDU-5186-zhx's submissions(Java+简单模拟)
- hdu 5186 zhx's submissions(模拟)
- HDU - 5186 - zhx's submissions (大数高精度)
- HDU - 5186 zhx's submissions
- HDU 5186 zhx's submissions 模拟,细节 难度:1
- HDU 5186 zhx's submissions (进制转换)
- hdu 5186 zhx's submissions 5187 zhx's contest快速幂小优化
- hdu 5186 zhx's submissions
- HDU - 5186 - zhx's submissions (精密塔尔苏斯)
- hdu 5186 zhx's submissions
- hdu 5186 zhx's submissions
- HDU 1228 模拟水题
- HDU 1031 Design T-Shirt 模拟 水题
- hdu 4891 模拟水题
- 【HDU 5532 Almost Sorted Array】水题,模拟
- HDU 1736(字符串模拟的水题)
- hdu 1491(Octorber 21st)(模拟水题)
- hdu 4891 模拟水题
- HDU 3635 Dragon Balls 并查集水题 模拟
- hdu 4530 小Q系列故事——大笨钟 模拟水题