C++刷題——2286: 逆序輸出單詞(串)

來源:互聯網
上載者:User

標籤:c++   iostream   namespace   string   

/* Copyright (c) 2014, 煙台大學電腦學院 * All rights reserved. * 檔案名稱:test.cpp * 陳丹妮 * 完成日期:2015年 5 月 25 日 * 版 本 號:v1.0 */Description輸入一個字串,空格作為單詞分隔字元,統計其中的單詞,並將單詞逆序輸出Input輸入一個字串Output逆序輸出單詞Sample InputI love you!Sample Outputyou love I!#include <iostream>#include <cstdio>using namespace std;int main(){    char a[500];    gets(a);    int i,j,n=0,m=0,s;    for(i=0;a[i]!=0;i++)        n++;    for(i=n-1;i>=0;--i)    {        if((a[i]>='a'&&a[i]<='z')||(a[i]>='A'&&a[i]<='Z'))        m=i;        else if(a[i]!=' ')            s=i;        if(i==0)            cout<<a[i];        if(a[i]==' ')        {            for(j=m;j<s;j++)                cout<<a[j];            cout<<" ";            s=i;        }    }    cout<<a[n-1];    return 0;}


學習心得:這道題寫了好久,好麻煩的,還是請教了大神,才寫了出來,好在寫出來了,繼續努力!

C++刷題——2286: 逆序輸出單詞(串)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.