2011-12-17 06:22:49
地址:http://acm.hdu.edu.cn/showproblem.php?pid=1982
题意:#表示空格 -无意义 数字对应'A'-'Z'。字符串处理。
代码:
# include <stdio.h>
# include <string.h>
char str[10010] ;
void output (char str[])
{
int i, flag = 0, num ;
for (i = 0 ; str[i] ; i++)
{
if (flag == 0)
{
if (str[i] >= '0' && str[i] <= '9')
{
num = str[i] -'0' ;
flag = 1 ;
}
else if (str[i] == '#') putchar (' ') ;
}
else
{
if (str[i] >= '0' && str[i] <= '9')
num = num * 10 + str[i]-'0' ;
else
{
putchar ('A'+num-1) ;
num = 0 ;
flag = 0 ;
if (str[i] == '#') putchar (' ') ;
}
}
}
printf ("\n") ;
}
int main ()
{
int T;
scanf ("%d%*c", &T) ;
while (T--)
{
gets (str) ;
str[strlen(str)+1] = '\0' ;
str[strlen(str)] = '-' ;
output (str) ;
}
return 0 ;
}