C++刷題——1938: 首字母變大寫,1938大寫

來源:互聯網
上載者:User

C++刷題——1938: 首字母變大寫,1938大寫
Description
輸入一個英文句子,將每個單詞的第一個字母改成大寫字母。 
Input
輸入資料包含多個測試執行個體,每個測試執行個體是一個長度不超過100的英文句子,佔一行。
Output

請輸出按照要求改寫後的英文句子。

(1)方法一/* All rights reserved. * 檔案名稱:test.cpp * 作者:陳丹妮 * 完成日期:2015年 5 月 21 日 * 版 本 號:v1.0 */#include <iostream>#include <cstdio>using namespace std;int main(){    char a[100];    while(gets(a))    {        int i;        a[0]=char(a[0]-32);        for(i=0;a[i]!='\0';i++)        {            if(a[i]==' ')                a[i+1]=char(a[i+1]-32);        }        for(i=0;a[i]!='\0';i++)        {            cout<<a[i];        }        cout<<endl;    }    return 0;}(2)方法二#include<iostream> #include <cstdio> using namespace std; int main() {     char a[100];     int i;     while(gets(a))     {         if(a[0]>='a'&&a[0]<='z')             a[0]-=32;         for(i=0; a[i]!='\0'; i++)         {             if(a[i]==' '&&a[i+1]>='a'&&a[i+1]<='z')                 a[i+1]-=32;         }         for(i=0; a[i]!='\0'; i++)         {             cout<<a[i];         }         cout<<endl;     }     return 0; } 

學習心得:不要忽視一些小細節,可能他就是影響全域的關鍵所在,要嚴謹細心,繼續努力!


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.