hdoj1062 Text Reverse(字符串操作题)

来源http://acm.hdu.edu.cn/showproblem.php?pid=1062

一开始的思路是将读入的字符串一个个分割成string输出

后面得到了结果但oj通不过,一直想不出哪里有问题。

后面换了一种思路,直接反着输出。

#include
#include
#include
#include
using namespace std;
int main()
{
	int t;
	scanf("%d",&t);
	char str[1005];
	getchar();
	while(t--)
	{
		int i,j,k;
		int len;
		gets(str);
		i=strlen(str);
		for(j=0;j=len;k--)
			printf("%c",str[k]);
			if(str[j]==' ')printf(" ");	
		}
		printf("\n");
		
		
	}
	return 0;
}


你可能感兴趣的:(oj)