Challenge
Careers
Class
Connect
로그인 후 문제풀이가 가능합니다.
코드 공유합니다. 더 깔끔하게 할 수 있는 방법 있으면 공유 부탁드립니다.
#include<iostream> #include<vector> using namespace std; class Map{ public: Map() : m(3, vector<int>(3, 0)){} void insert(int y, int xs[3]) { this->m[y] = vector<int>{xs[0], xs[1], xs[2]}; } int MinCost(){ int cost = 999; for (int n = 0; n < 3; n++){ int temp_cost = 999; temp_cost = min( abs(this->m[n][1] - this->m[n][0]) + abs(this->m[n][2] - this->m[n][0]), abs(this->m[1][n] - this->m[0][n]) + abs(this->m[2][n] - this->m[0][n]) ); cost = min(cost, temp_cost); } return cost; } private: vecto...
C초보가 복잡하게 푼 C언어 코드 공유합니다.. 간단하게 할 방법 있으면 공유해쥬세요,,
#include <stdio.h> #include <stdlib.h> int main(void) { int one[3]={0,0,0},two[3]={0,0,0},three[3]={0,0,0}; int num[3]={0,0,0}; int min=0; scanf("%d %d %d",&one[0],&one[1],&one[2]); scanf("%d %d %d",&two[0],&two[1],&two[2]); scanf("%d %d %d",&three[0],&three[1],&three[2]); for(int i=0;i<3;i++){ if (one[i]==two[i]&&two[i]==three[i]&&one[i]==three[i]){ num[i]=0; } else{ int a=one[i],b=two[i],c=three[i]; if(a!=c)num[i] = abs(a - b) + abs(b - c); else num[i] = abs(a-b); } } for(int i=0;i<2;i++){ ...
4, 8이 틀립니다.. 반례 있을까요?
def find_h(arr): min = 10 for low in arr : temp_low = low.copy() temp_low.sort() cur = temp_low[1] + temp_low[2] - temp_low[0] * 2 if cur < min : min = cur return min def find_v(arr): min = 10 for i in range(3): low = [arr[0][i], arr[1][i], arr[2][i]] low.sort() cur = low[1] + low[2] - low[0] * 2 if cur < min : min = cur return min ground1 = list(map(int, input().split())) ground2 = list(map(int, input().split())) ground3 = list(map(int, input().split())) ground = [ground1, ground2, ground3] ...
파이썬 완성 답 코드 공유
import sys row = [] result_list = [] for i in range(3): row = list(map(int, input().split())) result_list.append(row) result = 0 min = 9999 ######################################### for i in range(len(result_list)): row = result_list[i] if len(set(row)) == 1: min = 0 break; else: base = row[0] for value in (row): if value != base: if abs(base-value) < min: min = abs(base-value) for col in range(3): col_value = [row[col] for row in result_list] if len(set(col_value)) == 1: min = 0 break; else:...
TC 4,8,10
Scanner sc = new Scanner(System.in); int[][] data = new int[3][3]; for (int i=0; i<3; i++) { data[i][0] = sc.nextInt(); data[i][1] = sc.nextInt(); data[i][2] = sc.nextInt(); }; int minN = 2; for(int i=0; i<3; i++) { if(data[i][0] == data[i][1] && data[i][1]== data[i][2] ) { minN = 0; break; } else { int abs1 = Math.abs(d...
테케 4, 8, 10, 11 에서 틀렸습니다가 나오는데 이유를 모르겠어요. 도움부탁드립니다.
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[][] arrs = new int[3][3]; for (int i = 0; i < 3; i++) { StringTokenizer st = new StringTokenizer(br.readLine()); int a = Integer.parseInt(st.nextToken()); int b = Integer.parseInt(st.nextToken()); int c = Integer.parseInt(st.nextToken()); a...
4, 7, 8, 10, 11 에서 오류가 나는 이유가 뭘까요..?
const readline = require("readline") const rl = readline.createInterface({ input: process.stdin, output: process.stdout }) let input = [] rl.on("line", (line) => { input.push(line) }).on("close", ()=> { const graph = [] for(let i=0; i<3; i++) { graph.push(input[i].split(" ").map(Number)) } let group = [] // 가로 for(let i=0; i<3; i++) { group.push(graph[i]) } // 세로 for(let i=0; i<3; i++) { group.push([graph[0][i],graph[1][i],graph[2][i]]) } let answer = 1e9 for(let g of group) { let result = ne...
테케 4번..
import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception{ BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int[][] map = new int[3][3]; StringTokenizer st; for(int i=0; i<3; i++) { st = new StringTokenizer(br.readLine()); for(int j=0; j<3; j++){ map[i][j] = Integer.parseInt(st.nextToken()); } ...
반례좀 알려주세용
const input = require('fs').readFileSync(0).toString().trim().split('\n') const arrRow = input.map(item=> item.split(' ').map(Number)) let arrCol = [[],[],[]] for (let i = 0; i < arrRow.length; i++) { arrCol[0].push(arrRow[i][0]) arrCol[1].push(arrRow[i][1]) arrCol[2].push(arrRow[i][2]) } function add(arr){ let countArr = [] for (let i = 0; i < 3; i++) { let count1 = 0; let count2 = 0; let count3 = 0; for (let j = 0; j < 3; j++) { ...