View Code of Problem 114

#include<stdio.h>
#include<string.h>
#include <ctype.h>
int main()
	{
		char arr[100] = { 0 };
		while (gets(arr) != NULL)
		{
			int i = 0;
			int len = strlen(arr);
			while (i < len)
			{
				while (i < len && !isalpha(arr[i]))
				{
					printf("%c", arr[i]);
					i++;     //i不断移动,指向单词第一个字母,同时遇到空格打印空格
				}
				int j = i; //i找到单词开头,让j去扫描单词,直到单词后的一个空格
				while (j < len && isalpha(arr[j])!=0)//需要有j<len条件,要不然越界
				{
					j++;
				}
				for (int k = j - 1; k >= i; k--)
				{
					printf("%c", arr[k]);
				}
				i = j;//把单词后的第一空格位置告诉i让他来扫描
			}
			printf("\n");
		}
		return 0;
	}

Double click to view unformatted code.


Back to problem 114