๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
โœจ Algorithm

[EPPER/C++] 14ํšŒ : ์‹ ๋ฌธ ๊ธฐ์‚ฌ

by nitronium102 2021. 8. 31.

 

ํ’€์ด

01. r(ํ–‰)๋งŒํผ for๋ฌธ์„ ๋Œ๋ ค ๋ฌธ์ž์—ด ํ•œ ํ–‰์„ ์ฝ์–ด์˜จ๋‹ค. 

02. c(์—ด)๋งŒํผ for๋ฌธ์„ ๋Œ๋ ค ๋ฌธ์ž์—ด ๋‚ด๋ถ€์˜ ๋ฌธ์ž๋ฅผ ํ•˜๋‚˜์”ฉ ์ฝ์–ด์˜จ๋‹ค.

    02-1. zc(ํ™•๋Œ€์—ด)๋งŒํผ for๋ฌธ์„ ๋Œ๋ ค ํ™•๋Œ€๋œ ๋ฌธ์ž์—ด์„ ๋งŒ๋“ ๋‹ค. ex) abc -> aabbcc

03. zc(ํ™•๋Œ€ํ–‰)๋งŒํผ for๋ฌธ์„ ๋Œ๋ ค ํ™•๋Œ€๋œ ๋ฌธ์ž์—ด์„ ๋ณต์‚ฌํ•œ๋‹ค.

//ํ”„๋กœ๊ทธ๋ž˜๋จธ์Šค์—์„œ๋Š” mainํ•จ์ˆ˜ ๋ฐ ์ž…์ถœ๋ ฅ๋ฌธ์ด ํ•„์š”ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๋Œ€์‹  solutionํ•จ์ˆ˜๋งŒ ์ž‘์„ฑํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

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

vector<string> solution(int r, int c, int zr, int zc, vector<string> words) {
    vector<string> answer;
    
	string resize = "";
	for (int i=0; i<r; i++) {
		// ๊ฐ€๋กœ๋กœ ํ™•๋Œ€
		for (int j=0; j<c; j++){
			for (int k=0; k<zc; k++){
				resize += words[i][j];
			}
		}
		// ์„ธ๋กœ๋กœ ํ™•๋Œ€
		for (int p=0; p<zr; p++){
				answer.push_back(resize);
		}
		resize = "";
	}

    return answer;
}

using namespace std;
int main() {
	int r, c, zr, zc;
	vector<string> answer, words;
	string temp;
	
	cin >> r >> c >> zr >> zc;
	
	for(int i=0; i<r; i++)
	{
		cin >> temp;
		if(temp.length()>c)
		{
			cout << "์ž…๋ ฅ ๋ฒ”์œ„๋ฅผ ์ดˆ๊ณผํ•˜์˜€์Šต๋‹ˆ๋‹ค.\n";
			exit(1);
		}
		words.push_back(temp);
	}
  
  answer = solution(r, c, zr, zc, words);
  
	for(auto i : answer)
	{
		cout << i << endl;
	}
	
	return 0;
}

๋Œ“๊ธ€