This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
기준이 되는 수를 정하고 그 수와 나머지를 비교하여 가장 낮은 수를 제일 앞으로 보내는 정렬입니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
각 테스트 케이스는 한 줄로 이루어져 있으며, 각 줄에 A와 B가 주어진다. (0 < A, B < 10)
출력
각 테스트 케이스마다 "Case #x: "를 출력한 다음, A+B를 출력한다. 테스트 케이스 번호는 1부터 시작한다.
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.StringTokenizer;
public class al11021 {
public static void main(String[] args) throws NumberFormatException, IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int t = Integer.parseInt(br.readLine());
for (int i = 1; i < t + 1; i++) {
StringTokenizer st = new StringTokenizer(br.readLine());
int a = Integer.parseInt(st.nextToken());
int b = Integer.parseInt(st.nextToken());
int sum = a + b;
bw.write("Case #" + i + ": " + sum + "\n");
}
bw.flush();
bw.close();
}
}
위 사이트에 가면 vue-cookie 라이브러리를 사용하는 법이 아주 친절하게 나와 있다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
터미널 창에 다음과 같이 입력하여 vue-cookie 라이브러리를 설치한다. 참고로 vue-cookies 라이브러리도 있는데, 거의 비슷하다.
package.json 파일의 dependencies를 살펴 보면 vue-cookie가 설치된 것을 확인할 수 있다.
쿠키를 생성하고 삭제하는 방법은 위 사이트에 예시로 설명이 아주 잘 되어 있다.
음..ㅎ 지금은 대충 이런 상태.
F12를 눌러서 Application > Cookies에 가면 아직 아무런 데이터가 없다. 물론 token도 없기 때문에 화면에 버튼은 Sign Up, Sign In이 보인다.
2. 쿠키 생성 - main.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
다음과 같이 SignIn.vue를 작성한다. 이메일과 비밀번호를 입력하고 버튼을 누르면 토큰이 생성됨과 동시에 홈 화면으로 전환되고 헤더 부분의 버튼들이 바뀌는 형식이다.
axios를 통해 서버와 post방식으로 통신하여 이메일과 비밀번호 값을 서버에 보내면 해당 사용자의 토큰 데이터를 받아올 수 있다.
그러면 40번째 줄과 같이 토큰을 accesstoken이라는 키로 쿠키에 저장할 수 있다.
쨘! 로그인을 하면 쿠키에 accesstoken이라는 이름으로 토큰값이 들어간 것을 확인할 수 있다.
또한 보여지는 화면에도 회원가입, 로그인 버튼은 사라지고 로그아웃, 내 장바구니 버튼으로 전환되었다.
이와 같은 로직이 필요한 이유는 로그인을 해야만 내 장바구니에 들어갈 수 있도록 해야 하기 때문이다.
4. 쿠키 삭제
쿠키를 삭제하는 법도 간단하다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters