๋ฐ์ํ
https://codeforces.com/problemset/problem/1077/A
์ฝ๋
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int t = scan.nextInt();
for(int tc=0; tc<t; tc++) {
int a = scan.nextInt(); // Right
int b = scan.nextInt(); // Left
int k = scan.nextInt(); // Jumps
int ans = 0; // Print
for(int i=0; i<k; i++)
ans += (i%2 == 0) ? a : -b;
System.out.println(ans);
}
scan.close();
}
}
ํ์ด
k๋ฒ ๋งํผ ์ ํํ๊ณ , a๋ ์ค๋ฅธ์ชฝ์ผ๋ก(+a) , b๋ ์ผ์ชฝ์ผ๋ก(-b) ์ ํ ํ๋ค.
์ต์ข ์ ์ผ๋ก ์์น๋ฅผ ์ถ๋ ฅํ๊ธฐ.
k๋ฒ๋์ ๋ฐ๋ณตํ๋ฉด์ ํ์์ผ๋ a๋ฅผ ๋ํ๊ณ , ์ง์์ผ๋ b๋ฅผ ๋นผ์ฃผ๋ฉด ๋.
๋ฐ์ํ
'Algorithm' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Codeforces] 1207A: There Are Two Types Of Burgers (0) | 2020.03.10 |
---|---|
[Codeforces] 1095A: Repeating Cipher (0) | 2020.03.09 |
ํ๋ก๊ทธ๋๋จธ์ค[Java] - ์์ฐ (0) | 2020.03.08 |
[Codeforces] 1285A: Mezo Playing Zoma (0) | 2020.03.08 |
ํ๋ก๊ทธ๋๋จธ์ค[Java] - ์์ ์ฐพ๊ธฐ (0) | 2020.03.07 |
๋๊ธ