2017年11月26日 星期日

[C_ST88-易] 依序重複輸出字串(C++)

[C_ST88-易] 依序重複輸出字串

問題描述 :
在 input 中寫入一行字串 , 執行程式後自動產生 output, 並將字串內容依序重複寫入 output 中
輸入說明 :
一行字串
輸出說明 :
一行字串
範例 :

輸入範例輸出範例
aaa
abaabb


  1. #include<iostream>  
  2. #include <string.h>  
  3.   
  4. using namespace std;  
  5. int main(){  
  6.     // [C_ST88-易] 依序重複輸出字串  
  7.     string input;  
  8.     while(cin >> input)  
  9.     {  
  10.         int len = input.size();  
  11.         char char_input[len];  
  12.         strcpy(char_input, input.c_str());    
  13.         for(int i = 0;i < len;i++)  
  14.         {  
  15.             if(i != len-1)  
  16.             {  
  17.                 cout << char_input[i] << char_input[i];  
  18.             }  
  19.             else  
  20.             {  
  21.                 cout << char_input[i] << char_input[i] << endl;  
  22.             }  
  23.         }  
  24.     }  
  25. }  

沒有留言:

張貼留言