您的位置:首页 > 其它

PAT-1009 说反话

2016-02-23 22:38 344 查看
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

#define MAX 100
int main()
{
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
char str[MAX], word[MAX][MAX];
gets(str);
int j = 0, k = 0;
char temp[MAX];
for (int i = 0; i < strlen(str); i++)
{
if (str[i] == ' ' || str[i] == '\0')
{
strcpy(word[k++], temp);
j = 0;
memset(temp, '\0', sizeof(temp));
continue;
}
temp[j++] = str[i];
if (i == strlen(str)-1)
strcpy(word[k++], temp);
}

for(k--; k >= 0; k--)
{
cout << word[k];
if (k != 0)
cout << " ";
}

return 0;
}
一年没写代码了,越写越烂。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: