[恢]hdu 2100
2011-12-15 06:42:37
地址:http://acm.hdu.edu.cn/showproblem.php?pid=2100
题意:中文。
mark:26进制高精度,没啥好说的。
代码:
# include <stdio.h>
# include <string.h>
char a[210], b[210] ;
int aa[210], bb[210], buff[210] ;
void s2n(char *s, int n[])
{
int i, len ;
n[0] = 1, n[1] = 0 ;
while (*s == 'A') s++ ;
len = strlen(s) ;
if (len == 0) return ;
n[0] = len ;
for (i = 0 ; i < len ; i++)
n[len-i] = s[i] - 'A' ;
}
void n2s(int n[], char s[])
{
int i ;
for (i = n[0] ; i >= 1 ; i--)
s[n[0]-i] = n[i] + 'A' ;
s[n[0]] = '\0' ;
}
void add(int n[], int m[], int rst[])
{
int *p, *q ;
int i, cc = 0 ;
if (n[0] > m[0]) p = m, q = n ;
else p = n, q = m ;
for (i = 1 ; i <= q[0] ; i++)
{
if (i <= p[0]) buff[i] = p[i] ;
else buff[i] = 0 ;
buff[i] += q[i] + cc ;
cc = buff[i] / 26 ;
buff[i] %= 26 ;
}
if (cc != 0) buff[i++] = cc ;
buff[0] = i-1 ;
for (i = 0 ; i <= buff[0] ;i++)
rst[i] = buff[i] ;
}
int main ()
{
while (~scanf ("%s%s", &a, &b))
{
s2n(a,aa) ;
s2n(b,bb) ;
add(aa,bb,aa) ;
n2s(aa, a) ;
puts (a) ;
}
return 0 ;
}