1009 说反话(20分)

#include <iostream>
#include <string.h>
#include <cmath>
using namespace std;

int main()
{
    char buf[100];
    int pos[80];
    cin.getline(buf,85);
    int j=1;
    pos[0]=-1;
    for(int i=0;i<strlen(buf);i++)
    {
        if(buf[i]==' ')
        {
            pos[j]=i;
            j++;
        }
    }
    pos[j]=strlen(buf);
    for(int k=j;k>0;k--)
    {
        for(int l=pos[k-1]+1;l<pos[k];l++)
        {
            cout<<buf[l];
        }
        if(k>1)
            cout<<" ";
        else
            cout<<endl;
    }
    return 0;
}

输入一行包含空格的字符串:


char buf[100];

cin.getline(buf,85);

猜你喜欢

转载自www.cnblogs.com/QRain/p/12220600.html
今日推荐