카테고리 없음

221223

Berylly 2022. 12. 23. 17:56

T. 김동식

 

자료의 종류, 데이터포맷

정형: 표 (데이터베이스 안 표 형태 데이터, SQL로 수집해서 활용)

반정형:  XML, JSON (Python이나 javascript의 객체 데이터타입을 이용해야함)

비정형: 텍스트

 

객체

key+value

 

HashTable 해시테이블

key+value, key값을 부여해 데이터를 찾는다, key값은 유일해야하면 무변.

 

연쇄법

해시테이블의 종류중 하나.

해시함수를 이용해 해시값을 얻어 mod연산을해(배열의 방번째 수로 나누어) 방에 배치하며, 

같은방에 배치될경우, 연쇄법으로(리스트) 연결한다.

 

#Python

>>> a={'a':'벨류다'}
>>> type(a)
<class 'dict'>
>>> type(a['a'])
<class 'str'>
>>>
//javascript

var obj2 = {'이건 key고':'이건 value다'};
document.write("이 오브젝트의 타입은 "+typeof(obj2)+"이다<br>");
document.write(obj2['이건 key고']);

 

알고리즘

알고리즘: 해결가능한 문제를 풀기위한 절차

자료구조(선형, 배열, 리스트, 스택..)를 잘 활용해야 성능(적은시간, 적은메모리)이 좋아진다.

 

 

 

Python

숫자맞추기게임

# 해적이 1~100범위안 정수를 하나 가지고 있다
import random
secret = random.randint(1, 100);
print("정답은",secret)
count = 0

while count < 6 :
    guess = int(input("숫자를 입력하세요: "))
    if guess < secret:
        count = count+1
        print("시도횟수가",5-count,"번 남았어요, 보다 큰수를 입력하세요\n")
    elif guess > secret:
        count = count+1
        print("시도횟수가",5-count,"번 남았어요, 보다 작은수를 입력하세요\n")
    else:
        count = count+1
        print(count,"번째 도전만에 맞췄어요, 축하합니다.")
        break
    if count == 5:
        print("도전회수를 모두 소진했습니다.") 
        break

 

+ 선생님 보완

count = count+1
count += 1

print("시도횟수가",5-count,"번 남았어요, 보다 큰수를 입력하세요\n")
print("시도횟수가 %d번 남았어요, 보다 작은수를 입력하세요\n" %(5-count))

 

 

 

JAVA

 

Scanner

221222에 적어놓은 java.util.Scanner s = new java.util.Scanner(System.in);의 다른방법을 공부했다.

import java.util.Scanner;
Scanner s =new Scanner(System.in);
s.nextInt();

java.util.Scanner s = new java.util.Scanner(System.in);
s.nextInt();

https://sanghee.tistory.com/63/#scanner_sanghee

 

221222

T. 김동식 JAVA 1001학번 Lee 국어(100점), 수학(50점) 1002학번 Kim 국어(70점), 수학(85점), 영어(100점) 클래스 Student, Subject를 생성해 두 학생의 과목성적과 총점을 출력하라. 0. 설계 1. Subject1 설정 private St

sanghee.tistory.com

 

 

//int를 String으로 바꿀때
Integer.toString(int값); 
String.valueOf(int값);

//String으로 int로 바꿀때
Integer.valueOf(String값);

 

 

JavaScript

 

숫자맞추기 게임

위 파이썬 숫자맞추기 게임을 자바스크립트로 구현했다.

var computer = Math.floor((Math.random() * (10 - 1) + 1)); //정답
var man;
var count = 0;
var correctOrNot = false;

alert("정답: "+computer);

while (count < 5) {
	man = prompt("숫자를 입력하세요.")
	if (man > computer) {
		count++;
		correctOrNot = false;
		alert("보다 작습니다. \n" + (5 - count) + "번의 도전횟수가 남았어요")
	} else if (man < computer) {
		count++;
		correctOrNot = false;
		alert("보다 큽니다. \n" + (5 - count) + "번의 도전횟수가 남았어요")
	} else {
		count++;
		correctOrNot = true;
		alert(count + "번 만에 정답을 맞췄습니다.");
		break;
	}
}

if(correctOrNot == false){
	alert("도전횟수가 모두 소진됬습니다");
}

 

 

구구단, table로 출력

  <style>
        table {
            border-collapse: collapse;
            width: 700px;
            text-align: center;
        }
        td{padding: .5rem 1rem;}
    </style>
<script>
        document.write(" <table border='1'>");
        for(var i=2;i<=9;i++){
            document.write("<tr>");
            for(var j=1;j<9;j++){
                document.write("<td>");
                document.write(i+"x"+ j+"=<b>"+i*j+"</b>");
                document.write("</td>");
            }
            document.write("</tr>");
        }
        document.write("</table>");

    </script>

 

 

function을 활용한 계산기

var num1 = 1;
var num2 = 2;

function add(num1, num2) {return num1+num2;}
function divi(num1, num2) {return num1-num2;}
function mul(num1, num2) {return num1*num2;}
function devi(num1, num2) {return num1/num2;}

document.write(num1+"과"+num2+" 더하기: "+add(num1, num2)+"<br>");
document.write(num1+"과"+num2+" 빼기: "+divi(num1, num2)+"<br>");
document.write(num1+"과"+num2+" 곱하기: "+mul(num1, num2)+"<br>");
document.write(num1+"과"+num2+" 나누기: "+devi(num1, num2)+"<br><br>");