본문으로 건너뛰기

· 약 3분
karais89

프로세스란?

  • 실행중인 프로그램
  • 주기억장치, CPU의 실행단위
  • 동적인 프로그램
  • 리소스와 스레드의 구성
  • 모든 프로세스는 하나 이상의 스레드를 가짐

스레드란?

  • 경량화된 프로세스
  • 프로세스 내에서 실제 작업을 수행함
  • 한 프로세스 내에서 동작되는 여러 실행의 흐름

스레드 장점

  • 시스템의 자원 소모가 줄어든다. 프로그램의 응답 시간이 단축된다
  • 프로세스 간 통신 방법에 비해 스레드간의 통신 방법이 훨씬 간단하다

스레드의 단점

  • 프로세스 밖에서 스레드 각각을 제어할 수 없다.
  • 여러 개의 스레드를 이용하는 프로그램을 작성하는 경우에는 주의 깊게 설계 해야 한다.
  • 미묘한 시간차나 잘못된 변수를 공유함으로써 오류가 발생할 수 있다.
  • 프로그램의 디버깅이 어렵다. 단일 프로세서 시스템에서는 효과를 기대하기 어렵다.

프로세스와 스레드의 차이점

메모리 사용에 대한 차이

프로세스는 독립적으로 실행됩니다. 자신만의 고유 메모리를 할당 받아서 사용합니다.

스레드는 한 프로세스 내의 여러 흐름으로서 프로세스 내 주소 공간이나 자원을 공유해서 실행합니다.

이러한 특성으로 인해 프로세스 간의 전환보다는 스레드 간의 전환 속도가 더 빠릅니다.

· 약 3분
karais89

문제 요약

  • 모든 학생들은 0에서 100까지의 등급을 받는다.
  • 40 미만의 점수는 실패한 등급이다.

샘은 대학 교수이며 아래와 같이 등급을 매긴다.

  • 등급간의 차이는 5씩 차이가 나며 등급과 3미만의 차이가 나면 다음 등급으로 반올림 한다.
  • 만약 38 미만등급이면 결과가 실패한 등급이므로 반올림 하지 않는다.
  • 예를들어 84점이면 85로 반올림 되고 29점이면 29이다.

내 소스

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {

static int[] solve(int[] grades){
// Complete this function
int[] finalGrades = new int[grades.Length];
for (int i = 0; i < grades.Length; i++)
{
// less than 38 fail grade
if (grades[i] < 38)
{
finalGrades[i] = grades[i];
}
else
{
int firstValue = grades[i] / 10 * 10;
int secondValue = grades[i] % 10;
int roundedValue = 0;
if (secondValue > 5)
{
roundedValue = firstValue + 10;
}
else
{
roundedValue = firstValue + 5;
}

if (roundedValue - grades[i] < 3)
{
finalGrades[i] = roundedValue;
}
else
{
finalGrades[i] = grades[i];
}
}
}
return finalGrades;
}

static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[] grades = new int[n];
for(int grades_i = 0; grades_i < n; grades_i++){
grades[grades_i] = Convert.ToInt32(Console.ReadLine());
}
int[] result = solve(grades);
Console.WriteLine(String.Join("\n", result));


}
}

nabila_ahmed의 답안

#include <bits/stdc++.h>
using namespace std;

void solution() {
int n, x;
cin>>n;
for(int i=0; i<n; i++){
cin>>x;
if(x>=38 and x%5>=3){
while(x%5!=0){
x++;
}
}
cout<<x<<endl;
}
}

int main () {
solution();
return 0;
}

enilaydagdemir의 답안

static int solve(int grade){
int result = grade;
if (grade >= 38)
{
if ((5 - (grade % 5) + grade) - grade < 3)
result = 5 - (grade % 5) + grade;
}
return result;
}

static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[] grades = new int[n];
for(int grades_i = 0; grades_i < n; grades_i++){
grades[grades_i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(solve(grades[grades_i]));
}
}

느낀점

내가 생각한거랑은 좀 다른 해결책을 제시함.

내 생각은

  1. fianlValue 값을 구한다.
  2. finalValue 에서 현재 값을 뺀다.
  3. 그 수의 차이가 3미만이면 finalValue 값 (반올림 한다)
  4. 그 수의 차이가 3이상이면 원래 값 (반올림 하지 않는다)

이런식으로 문제를 해결했다.

등급이 점수 5를 기준으로 나누어 지므로.

(5 - (grade % 5) + grade) 이런식으로도 다음 등급을 파악할 수 있다.

ex) 71

5 - (1) + 71 = 75

ex) 89

5 - (4) + 89 = 90

· 약 2분
karais89

문제 요약

일반 시간을 군대 시간으로 변경하기.

Sample Input

07:05:45PM

Sample Output

19:05:45

내 소스

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {

static string timeConversion(string s) {
// Complete this function
string time = s.Substring(0, 8);
string timeFormat = s.Substring(8);

string[] timeSplit = time.Split(':');
int hour = 0;
if (timeFormat == "PM")
{
hour = Convert.ToInt32(timeSplit[0]) + 12;
if (hour == 24)
{
hour = 12;
}
}
else
{
hour = Convert.ToInt32(timeSplit[0]);
if (hour == 12)
{
hour = 0;
}
}
return string.Format("{0:00}:{1:00}:{2:00}", hour, timeSplit[1], timeSplit[2]);
}

static void Main(String[] args) {
string s = Console.ReadLine();
string result = timeConversion(s);
Console.WriteLine(result);
}
}

vatsalchanana의 답안

#include<iostream>
#include<cstdio>

using namespace std;

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

int n = s.length();
int hh, mm, ss;
hh = (s[0] - '0') * 10 + (s[1] - '0');
mm = (s[3] - '0') * 10 + (s[4] - '0');
ss = (s[6] - '0') * 10 + (s[7] - '0');

if (hh < 12 && s[8] == 'P') hh += 12;
if (hh == 12 && s[8] == 'A') hh = 0;

printf("%02d:%02d:%02d\n", hh, mm, ss);

return 0;
}

Jashin의 답안

public static void main(String[] args) {

Scanner scan = new Scanner(System.in);
String time = scan.next();
String tArr[] = time.split(":");
String AmPm = tArr[2].substring(2,4);
int hh,mm,ss;
hh = Integer.parseInt(tArr[0]);
mm = Integer.parseInt(tArr[1]);
ss = Integer.parseInt(tArr[2].substring(0,2));

String checkPM = "PM",checkAM ="AM";
int h = hh;
if(AmPm.equals(checkAM) && hh==12)
h=0;
else if(AmPm.equals(checkPM)&& hh<12)
h+=12;

System.out.printf("%02d:%02d:%02d",h,mm,ss);
}

느낀점

AM, PM을 군대 시간으로 바꾸는 문제이다.

· 약 3분
karais89

문제 요약

첫번째 인수로는 양초의 개수를 받고

나머지 인수는 그 양초의 높이를 각각 받는다.

콜린은 양초의 높이가 가장 큰 것들만 불을 끌 수 있다.

그녀가 성공적으로 날려버릴 수 있는 양초를 출력해라.

Sample Input

4
3 2 1 3

Sample Output

2

내 소스

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {

static int birthdayCakeCandles(int n, int[] ar) {
// Complete this function
int max = ar[0];
int maxCount = 0;

for (int i = 0; i < n; i++)
{
if (max < ar[i])
{
max = ar[i];
}
}

for (int i = 0; i < n; i++)
{
if (ar[i] == max)
{
maxCount++;
}
}

return maxCount;
}

static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());
string[] ar_temp = Console.ReadLine().Split(' ');
int[] ar = Array.ConvertAll(ar_temp,Int32.Parse);
int result = birthdayCakeCandles(n, ar);
Console.WriteLine(result);
}
}

shashank21j의 답안

자바의 경우는 나와 거의 같은 식으로 풀었다.

import java.util.*;

public class Solution {

public static void main(String[] args) {
Scanner scan = new Scanner(System.in);

// the number of candles
int n = scan.nextInt();

// store the current maximum height of any candle, initialize to the minimum possible height of any candle
int maxHeight = 1;

// count the number of candles having the maximum height
int countMax = 0;

for(int i = 0; i < n; i++) {
int tmp = scan.nextInt();

// if you read in a value larger than maxHeight, set new maxHeight
if(tmp > maxHeight) {
maxHeight = tmp;
countMax = 1;
}
// if you read a value equal to the current value of maxHeight
else if(tmp == maxHeight) {
// increment the count of candles having maximum height
countMax++;
}
}
scan.close();

System.out.println(countMax);
}
}

파이썬의 경우는 3줄로 표현이 가능하다.

n = input()
arr = map(int, raw_input().split())
print arr.count(max(arr))

느낀점

문제 자체는 그냥 주어진 배열의 맥스값을 구하고, 맥스값의 개수를 구하는 문제이다.

· 약 2분
karais89

문제 요약

5개의 정수가 주어지고 그 중에 4개를 선택할때 나올 수 있는 최소값과 최대값을 구해라.

Sample Input

1 2 3 4 5

Sample Output

10 14

내 소스

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {

static void Main(String[] args) {
string[] arr_temp = Console.ReadLine().Split(' ');
int[] arr = Array.ConvertAll(arr_temp,Int32.Parse);

int min = arr[0];
int max = arr[0];
long sum = 0;
for (int i = 0; i < arr.Length; i++)
{
if (min > arr[i])
{
min = arr[i];
}

if (max < arr[i])
{
max = arr[i];
}

sum += arr[i];
}

Console.Write("{0} {1}", sum-max, sum-min);
}
}

느낀점

문제 자체는 5개 중에 4개를 선택해서 나올 수 있는 최소값과 최대값을 구하는 것이다.

하지만 이걸 다른식으로 생각하면 5개 중에 가장 큰 수를 선택해서 뺀 값이 최소값 5개 중에 가장 작은 값을 구해서 뺀 값이 최대값이다.

· 약 2분
karais89

문제 요약

계단 문제.

n을 입력받으면 그 n만큼의 계단모양의 #을 출력해라.

Sample Input

6 

Sample Output

     #
##
###
####
#####
######

내 소스

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {

static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());

for (int i = 0; i < n; i++)
{
// space
for (int j = n-i-1; j > 0; j--)
{
Console.Write(' ');
}

// #
for (int k = 0; k < i+1; k++)
{
Console.Write('#');
}

// new line
Console.WriteLine();
}
}
}

vatsalchanana의 답안

#include<iostream>

using namespace std;

int main () {
int height;
cin >> height;

for (int i = 1; i <= height; i++) {
for (int j = 0; j < i; j++) {
if(j==0) {
//Printing spaces
for(int t = 0; t < height - i; t++) cout << " ";
}
//Print hashes
cout << "#";
}
cout << endl;
}
return 0;
}

svecon 답안

이런식으로 한줄로 표현할 수도 있다.

using System;
class Solution
{
static void Main(String[] args)
{
int N = int.Parse(Console.ReadLine());
for (int i = 0; i < N; i++)
Console.WriteLine(new String('#', i + 1).PadLeft(N, ' '));
}
}

느낀점

학부 시간에 c를 배울때 하는 * 출력하는 문제랑 똑같은 문제.

· 약 2분
karais89

문제 요약

첫번째 인풋은 입력받을 정수의 개수 나머지 인풋은 그 정수의 값들을 받는다.

3개의 라인으로 출력해라.

  1. 양수의 개수 / 정수의 개수
  2. 음수의 개수 / 정수의 개수
  3. 0의 개수 / 정수의 개수

소수 6째 자리까지 표현 해야된다.

Sample Input

6
-4 3 -9 0 4 1
  • 양수 : 3개(3,4,1)
  • 음수 : 2개(-4,-9)
  • 0 : 1개(0)

Sample OutPut

0.500000
0.333333
0.166667
  1. 3/6 = 0.500000
  2. 2/6 = 0.333333
  3. 1/6 = 0.166667

내 소스

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {

static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());
string[] arr_temp = Console.ReadLine().Split(' ');
int[] arr = Array.ConvertAll(arr_temp,Int32.Parse);

int plusCount = 0;
int minusCount = 0;
int zeroCount = 0;

for (int i = 0; i < n ; i++)
{
if (arr[i] > 0)
plusCount++;
else if (arr[i] < 0)
minusCount++;
else
zeroCount++;
}

Console.WriteLine(string.Format("{0:f6}", (float)plusCount/n));
Console.WriteLine(string.Format("{0:f6}", (float)minusCount/n));
Console.WriteLine(string.Format("{0:f6}", (float)zeroCount/n));
}
}

vatsalchanana의 답안

#include<iostream>

using namespace std;

int main() {
int n;
cin >> n;

float pl = 0, mn = 0, zr = 0;

for (int i = 0; i < n; i++) {
int val;
cin >> val;
zr += (val == 0);
pl += (val > 0);
mn += (val < 0);
}

zr = zr / (double)n;
pl = pl / (double)n;
mn = mn / (double)n;

printf("%0.06lf\n%0.06lf\n%0.06lf\n", pl, mn, zr);
return 0;
}

느낀점

문제 자체는 크게 어려운게 없다.

콘솔 출력시 서식문자를 가지고 출력하는 방법만 알면 쉬운 문제다.

· 약 3분
karais89

문제 요약

첫번째 input은 N x N 배열을 만들어 줄때 필요한 N의 개수

그리고 나머지 input은 그 배열의 각각의 인수의 값.

배열의 첫번째 대각선의 합(왼쪽 상단에서 시작해서 오른쪽 하단으로 끝나는)과 두번째 대각선(오른쪽 상단에서 시작해서 왼쪽 하단으로 끝나는)의 차를 절대값을 구하는 문제.

ex)

3
11 2 4
4 5 6
10 8 -12
  • 첫번째 대각선의 합 : 11 + 5 - 12 = 4
  • 두번째 대각선의 합 : 4 + 5 + 10 = 19
  • 두 대각선의 차이의 절대값 : |4 - 19| = 15

내 소스

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {

static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());
int[][] a = new int[n][];
for(int a_i = 0; a_i < n; a_i++){
string[] a_temp = Console.ReadLine().Split(' ');
a[a_i] = Array.ConvertAll(a_temp,Int32.Parse);
}

// primary diagonal (0,0), (1,1), (2,2)
int primarySum = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i == j)
primarySum += a[i][j];
}
}

// secondary diagonal (2,0) (1,1) (0,2)
int secondarySum = 0;
for (int i = 0; i < n; i++)
{
for (int j = 0; j < n; j++)
{
if (i+j == n-1)
secondarySum += a[i][j];
}
}

int diff = primarySum - secondarySum;
Console.Write(Math.Abs(diff));
}
}

vatsalchanana의 답안

#include <iostream>

using namespace std;

int main() {
int n;
cin >> n;

int arr[n][n];

long long int d1=0; //First Diagonal
long long int d2=0; //Second Diagonal

for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> arr[i][j];
if (i == j) d1 += arr[i][j];
if (i == n - j - 1) d2 += arr[i][j];
}
}

cout << abs(d1 - d2) << endl; //Absolute difference of the sums across the diagonals
return 0;
}

느낀점

배열에서 첫 번째 대각선과 두번째 대각선의 인덱스 값을 구하는 방법을 생각하면 풀 수 있는 문제.

나의 경우에는 첫번째 대각선과 두번째 대각선을 각각 for문으로 돌려서 푸는 방식을 택하였다.

vatsalchanana의 경우는 for문 하나에서 대각선의 합을 구해버리는 방식으로 문제를 해결 하였다.

· 약 4분
karais89

book image

스프트웨어 개발자 자기 계발서적

기간

4일

목적

예전에 도서관에서 책을 읽고 나서, 좋은 책이란 생각을 했다.

ebook으로 구매 함.

소프트웨어 개발자로 살아가면서 도움이 될 법한 글이 많은 것 같아서 구입.

리뷰

책은 아래와 같은 내용을 다룬다.

  • 경력 관리 방법
  • 효과적인 학습 방법
  • 재무관리 및 몸과 마음의 건강을 관리하는 데 필요한 기본적인 지식

책 제목의 소프트 스킬은 핵심 업무 능력을 의미하는 하드 스킬과 대조되는, 대인 관계, 언어, 습관 커뮤니케이션, 리더십과 같은 기술을 의미한다.

좋은 소프트웨어 개발자가 되는 법을 알려주는 책

좋은 소프트웨어 개발자는 자신의 경력을 관리하고 목표를 성취하며 삶을 즐기면서 살아가는 사람이다. 물론 코딩, 문제해결, 단위 테스트 작성을 능숙하게 하는 것도 중요하다.

책은 크게 경력, 신체, 정신 영혼의 네가지 주제를 다룬다.

책 마지막 파트의 실천하기 부분을 참고해서 실제로 적용해 보는것도 하나의 방법 일 것 같다.

정확한 사례를 들어서 설명하여 누구든 이대로 실천한다면 도움이 될 만한 방법들을 가르쳐주고 있다.

나중에 책에 파트 별로 따로 정리해서 실천을 해봐야 될 것 같다.

두고 두고 봐야 될 책인 것 같다.

참조 링크

참조 서적

  • 데일 카네기의 인간관계론(How to Win Friends and Influence People)
  • 최고의 나를 꺼내라(The War of Art: Break Through the Blocks and Win Your Inner Creative Battles)
  • 습관의 힘(The Power of Habit: Why We Do What We Do in Life and Business)
  • 백만장자 마인드의 비밀(Secrets of the Millionaire Mind: Mastering the Inner Game of Wealth)
  • 액트 빅, 씽크 스몰 : 실력이 열정을 이긴다(So Good They Can't Ignore You)
  • 에릭 리스의 린스타트업
  • 다니엘 핑크의 책 : 드라이브(Drive : The Surprising Truth about What Motivates US)
  • 똑바로 일하라(Rework)

평점 및 느낀점

자기 계발 서적 중 한 손가락 안에 드는 책.

5/5

· 약 2분
karais89

문제 요약

첫 번째 인수는 배열의 인자 개수. 두번째 인자는 배열을 인자로 받는다.

배열의 크기의 합을 구하는 문제이다. 배열의 합은 매우 크므로 c/c++은 long long 자료형을 사용하고,

자바의 경우 long 자료형을 사용해서 배열의 합을 구하자.

내 소스

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
class Solution {

static long aVeryBigSum(int n, long[] ar) {
// Complete this function
long sum = 0;
for (int i = 0; i < n ; i++)
{
sum += ar[i];
}
return sum;
}

static void Main(String[] args) {
int n = Convert.ToInt32(Console.ReadLine());
string[] ar_temp = Console.ReadLine().Split(' ');
long[] ar = Array.ConvertAll(ar_temp,Int64.Parse);
long result = aVeryBigSum(n, ar);
Console.WriteLine(result);
}
}

느낀점

배열의 합을 구하면 된다.

배열의 합은 매우 크므로 long 자료형을 사용해서 구해주면 끝..

HackerRank Warup 2번째 문제와 같은 방식으로 구했다.