PAT-1009 说反话

来源:互联网 发布:免费听书软件下载 编辑:程序博客网 时间:2024/04/30 22:23
#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;#define MAX 100int 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;}
一年没写代码了,越写越烂。
0 0
原创粉丝点击