Try   HackMD
tags: tgirc早修book

Ch.00 題目練習

輸出

題目

  1. Zerojudge d483: hello, world
題解
  1. Zerojudge d483: hello, world
#include <iostream> using namespace std; int main(){ cout<<"hello, world"; return 0; }

單純的輸出而已,有錯的可能是輸出的格式錯誤。
可以直接複製範例測資,就能確保格式正確了。

輸入

題目

  1. Zerojudge a001: 哈囉
題解
  1. Zerojudge a001: 哈囉
#include <iostream> using namespace std; int main(){ string s; cin>>s; cout<<"hello, "<<s<<"\n"; return 0; }

相較於上題多了個輸入,透過 string 宣告一個字串 s,再進行輸入即可。
輸出時先輸出題目要求的 hello, ,再輸出裝載輸入訊息的變數 s