Algorithm
[프로그래머스] 비밀지도
일등하이
2023. 1. 29. 10:34
반응형
https://school.programmers.co.kr/learn/courses/30/lessons/17681
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
1단계

using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
namespace BOJ
{
class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
StreamWriter sw = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
int n = int.Parse(sr.ReadLine());
//testcase 입력
for (int t = 0; t < 2; t++)
{
int[] arr1 = Array.ConvertAll(sr.ReadLine().Split(), int.Parse);
// 5
// 9 20 28 18 11
// 30 1 21 17 28
for (int i = 0; i < arr1.Length; i++)
{
//convert.tostring : 10진수를 2진수로 변경
//padleft : n자리로 만들고 '0'을 채움
string binary = Convert.ToString(arr1[i], 2).PadLeft(n, '0');
sw.WriteLine(binary);
}
sw.WriteLine();
}
sr.Close();
sw.Close();
}
}
}


using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Text;
// 5
// 9 20 28 18 11
// 30 1 21 17 28
namespace BOJ
{
class Program
{
static void Main(string[] args)
{
StreamReader sr = new StreamReader(new BufferedStream(Console.OpenStandardInput()));
StreamWriter sw = new StreamWriter(new BufferedStream(Console.OpenStandardOutput()));
int n = int.Parse(sr.ReadLine());
int[] arr1 = Array.ConvertAll(sr.ReadLine().Split(' '), int.Parse);
int[] arr2 = Array.ConvertAll(sr.ReadLine().Split(' '), int.Parse);
string[] map1 = new string[n];
string[] map2 = new string[n];
for (int i = 0; i <n; i++)
{
map1[i] = Convert.ToString(arr1[i], 2).PadLeft(n, '0');
sw.Write(map1[i]);
sw.Write("\t");
map2[i] = Convert.ToString(arr2[i], 2).PadLeft(n, '0');
sw.Write(map2[i]);
sw.WriteLine();
}
List<string> answer = new List<string>();
for(int i = 0; i < n; i++)
{
var num1 = Convert.ToByte(map1[i], 2);
var num2 = Convert.ToByte(map2[i], 2);
var or = Convert.ToString(num1 | num2, 2).PadLeft(n, '0');
StringBuilder sb = new StringBuilder();
for (int j = 0; j < or.Length; j++)
{
sw.Write(or[j]);
if (or[j] == '0')
sb.Append(" ");
else
sb.Append("#");
}
sw.WriteLine(sb.ToString());
//sw.WriteLine();
answer.Add(sb.ToString());
}
// 6
// 46 33 33 22 31 50
// 27 56 19 14 14 10
foreach (var x in answer)
{
//sw.WriteLine(x);
}
sr.Close();
sw.Close();
}
}
}
c++
#include <string>
#include <vector>
using namespace std;
vector<string> solution(int n, vector<int> arr1, vector<int> arr2) {
vector<string> answer;
for(int i = 0; i<n; i++){
arr1[i] = arr1[i] | arr2[i];
string ans = "";
for(int j = 0; j<n; j++){
if(arr1[i] % 2 == 0)
ans = " " + ans;
else
ans = "#" + ans;
arr1[i] = arr1[i] >> 1;
}
answer.push_back(ans);
}
return answer;
}
반응형