careercup5

Write a method to replace all spaces in a string with ‘%20’
還是用比較核武的字符串流吧~~剛開始的題目還是比較簡單的。

#include <iostream>
#include <sstream>
#include <string>
using namespace std;

int main(){
   string st,buff;
   getline(cin ,st);
   stringstream ss(st);
   ss>>buff;
   cout<<buff;
   while(ss>>buff)
	   cout<<"%20"<<buff;
}


發佈了32 篇原創文章 · 獲贊 1 · 訪問量 1萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章