문제 : https://www.acmicpc.net/problem/18245


[알고리즘풀이]

i 번 째 문장에서는 i 칸씩 건너뛰어야되므로, 입력을 받으며 i 칸씩 건너뛰며 출력한 후 i 를 1씩 증가시킵니다.

#include<iostream>
#include<string>

using namespace std;

int main(void) {
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	int i = 2;
	string A, B = "Was it a cat I saw?";
	while (1) {
		getline(cin, A);
		if (A == B)
			break;
		for (int j = 0; j < A.length(); j += i)
			cout << A[j];
		cout << '\n';
		i++;
	}
}

 

+ Recent posts