[BOJ / C++] 11721 열 개씩 끊어 출력하기

Seulguo·2022년 7월 11일
0

Algorithm

목록 보기
35/185
post-thumbnail

🐣 문제

링크 : https://www.acmicpc.net/problem/11721


🐥 코드

#include <iostream>
#include <string>

using namespace std;

int main() {
  string s = "";
  cin >> s;

  int n = s.size() / 10 ;
  if(n % 10 != 0) n++;

  if(n == 0){
    cout << s;
    return 0;
  }
  
  int pre = 0;
  int now = 10;
  
  for(int i = 0; i < n; i++){
    for(int j = pre; j < now; j++){
      cout << s[j];
    }
      cout << "\n";
      pre += 10;
      now += 10;

      if(now > s.size()) now = s.size();
  }
  
  return 0;
}

0개의 댓글