구현(Implementation)
백준 12790번: Mini Fantasy War
cepiloth
2018. 6. 13. 16:26
반응형
https://www.acmicpc.net/problem/12790
1. 문제 요약
입력받은 정수로 캐릭터의 전투력을 출력하는 문제
2. 알고리즘
문제 그대로 구현 하면 됩니다.
3. 코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include<stdio.h> int chp(int h){ return h < 1 ? 1 : h; } int cmp(int m){ return m < 1 ? 5 : 5 * m; } int cat(int at){ return at < 0 ? 0 : 2 * at; } int main(){ int hp, mp, at, am, i, n, k, total = 0; scanf("%d", &n); while (n > 0){ hp = mp = at = am = total = 0; for (i = 0; i < 8; i++){ scanf("%d", &k); switch (i%4) { case 0: hp += k; break; case 1: mp += k; break; case 2: at += k; break; case 3: am += k; break; } } total = chp(hp) + cmp(mp) + cat(at) + (am*2); printf("%d\n", total); n--; } return 0; } | cs |
반응형