PAT 1009. 说反话 (20)

 

代码

#include<bits/stdc++.h>

using namespace std;

char s[100];
string b[100];
int main()
{
    int i,j,k,t;
    gets(s);
    int n=strlen(s);
    cout<<n<<endl;
    for(i=0,j=0;i<n;i++)
    {
        if(s[i]==' ')  
        {
            b[j][k]='\0';
            j++;   k=0;
        }
        else
        {
            b[j][k++]=s[i];
        }
    }
    
    for(t=j-1;t>=0;t--)
    {
        cout<<b[t]<<endl;
    }
    return 0;
}

 

posted @ 2016-04-07 22:45  Gssol  阅读(140)  评论(0编辑  收藏  举报