DS study : array
This commit is contained in:
parent
cadfcc9c54
commit
b5dafd864e
13
code_study/data_structure/DS_array.c
Normal file
13
code_study/data_structure/DS_array.c
Normal file
@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(){
|
||||
int numbers[10] = {5, 29, -10, 55, 1, 9, 8, 15, 42, -7};
|
||||
int min = numbers[0], max = numbers[0];
|
||||
for(int i=0; i<10; i++){
|
||||
if(numbers[i]<min) min = numbers[i];
|
||||
if(numbers[i]>max) max = numbers[i];
|
||||
}
|
||||
|
||||
printf("최소값 : %d\n최대값 : %d\n to. 리노",min, max);
|
||||
return 0;
|
||||
}
|
||||
23
code_study/data_structure/DS_array.java
Normal file
23
code_study/data_structure/DS_array.java
Normal file
@ -0,0 +1,23 @@
|
||||
import java.util.*;
|
||||
|
||||
public class DS_array {
|
||||
public static void main(String[] args) {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
ArrayList<Integer> numbers = new ArrayList<>();
|
||||
String[] input = sc.nextLine().split(" ");
|
||||
sc.close();
|
||||
for(String num : input){
|
||||
numbers.add(Integer.parseInt(num));
|
||||
}
|
||||
|
||||
int min = numbers.get(0);
|
||||
int max = numbers.get(0);
|
||||
for(int num : numbers){
|
||||
min = Math.min(min, num);
|
||||
max = Math.max(max, num);
|
||||
}
|
||||
|
||||
System.out.printf("To. Rino\n최소값 : %d\n최대값 : %d\nFrom. 한심한 예찬..\n",min,max);
|
||||
|
||||
}
|
||||
}
|
||||
9
code_study/data_structure/DS_array.py
Normal file
9
code_study/data_structure/DS_array.py
Normal file
@ -0,0 +1,9 @@
|
||||
numbers = list(map(int, input().split()))
|
||||
min_value = max_value = numbers[0]
|
||||
|
||||
for num in numbers:
|
||||
min_value = num if num < min_value else min_value
|
||||
max_value = num if num > max_value else max_value
|
||||
|
||||
result = "To. 건방진 리노\n최소값: " + str(min_value) + "\n최대값: " + str(max_value) + "\nFrom. 조금은 너와 가까워지고픈 예찬"
|
||||
print(result)
|
||||
19
code_study/data_structure/DS_array.swift
Normal file
19
code_study/data_structure/DS_array.swift
Normal file
@ -0,0 +1,19 @@
|
||||
if let input = readLine(),
|
||||
let numbers = {
|
||||
let tempNumbers = input.split(separator: " ").compactMap({Int($0)})
|
||||
return tempNumbers.isEmpty ? nil : tempNumbers
|
||||
}() {
|
||||
|
||||
var min = numbers[0]
|
||||
var max = numbers[0]
|
||||
|
||||
for num in numbers {
|
||||
min = min > num ? num : min
|
||||
max = max < num ? num : max
|
||||
}
|
||||
|
||||
print("To. Cuty Rino\n최소값 : \(min)\n최대값 : \(max)\n")
|
||||
|
||||
} else {
|
||||
print("좀 더 노력할게.. 리노야...")
|
||||
}
|
||||
9
code_study/data_structure/DS_array.ts
Normal file
9
code_study/data_structure/DS_array.ts
Normal file
@ -0,0 +1,9 @@
|
||||
const numbers: number[] = require("fs").readFileSync(0, "utf8").toString().split(' ').map(Number);
|
||||
let [min, max]: number[] = [numbers[0], numbers[0]]
|
||||
|
||||
for(let num of numbers){
|
||||
min = min > num ? num : min;
|
||||
max = max < num ? num : max;
|
||||
}
|
||||
|
||||
console.log(min, max);
|
||||
Loading…
x
Reference in New Issue
Block a user