[恢]hdu 1062

2011-12-15 15:02:44

地址:http://acm.hdu.edu.cn/showproblem.php?pid=1062

题意:倒序单词输出。

mark:wa了一次,把范围1000看成100, 2B了。

代码:

# include <stdio.h>


char str[1100] ;
char word[1100] ;


void gao(char str[])
{
word[100] = '\0' ;
int i, cnt = 99 ;
for (i = 0 ; str[i] ; i++)
{
if (str[i] == ' ')
{
printf ("%s ", word+cnt+1) ;
cnt = 100 ;
}
else word[cnt--] = str[i] ;
}
if (cnt != 100)
printf ("%s", word+cnt+1) ;
printf ("\n") ;
}


int main ()
{
int n ;
scanf ("%d%*c", &n) ;
while (n--)
{
gets (str) ;
gao(str) ;
}
return 0 ;
}



原文地址:https://www.cnblogs.com/lzsz1212/p/2314783.html