解题报告不写了,光贴个代码。。主要是注意各个符号,然后字符串的变换等等。
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <bitset>
using namespace std;
// 大数,内存处理
const int INF = 0x3f3f3f3f;
#define ll long long int
#define MEM(a) memset(a, 0, sizeof(a))
#define MEMM(a) memset(b, -1, sizeof(b))
#define DEB(x, n) cout << (x) << " " << (n) << endl;
#define putCR printf("\n")
const int maxn = 210;
char num[maxn];
char a[maxn], b[maxn];
int n, B;
inline int getnum(char &a)
{
if(a >= ‘0‘ && a <= ‘9‘) return a-‘0‘;
else return a-‘a‘+10;
}
inline char cal(char &a, char &b)
{
int t1 = getnum(a);
int t2 = getnum(b);
t1 = (t1 + t2) % B;
if(t1 < 10) return t1+‘0‘;
else return t1-10+‘a‘;
}
// 字符串翻转
inline void trans(char *a)
{
int len = strlen(a);
// printf("%d", len);
for(int i = 0; i < len/2; i++)
swap(a[i], a[len-i-1]);
}
inline void add(char *a, char *b)
{
int len1 = strlen(a);
int len2 = strlen(b);
int len, rest;
if(len1 > len2)
{
len = len2;
rest = len1;
}
else
{
len = len1;
rest = len2;
}
for(int i = 0; i < len; i++)
a[i] = cal(a[i], b[i]);
if(rest == len1) return;
else for(int i = len; i < len2; i++) a[i] = b[i];
}
int main()
{
#ifdef DEBUG
freopen("input", "r", stdin);
#endif
int len;
while(scanf("%d%d", &n, &B)!= EOF)
{
memset(num, 0, sizeof(num));
for(int i = 0; i <n ;i++)
{
scanf("%s", a);
trans(a); add(num, a);
}
trans(num);
len = strlen(num);
int i;
for(i = 0; i < len; i++)
if(num[i] != ‘0‘) break;
if(i == len)
printf("0");
else for(;i < len; i++)
printf("%c", num[i]);
printf("\n");
}
return 0;
}
BestCoder #33 zhx's submissions
时间: 2024-10-12 16:24:26