티스토리 뷰

알고리즘/SWEA

[SWEA 1223] 계산기2

히더 2018. 8. 10. 17:11

출처 : https://www.swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AV14nnAaAFACFAYD


#include <stdio.h>

#include <algorithm>


int N, result;

char a[150];


int main()

{

for (int t = 1; t < 11;t++)

{

scanf("%d", &N); scanf("%s", a); result = 0;

int n1 = 0, n2 = 0, s1[150], s2[150];


for (int i = 0; i < N; i++) {

if (a[i] == '+') s2[n2++] = '+';

else if (a[i] == '*') {

s1[n1 - 1] = s1[n1 - 1] * (a[i + 1] - '0');

i++;

}

else s1[n1++] = a[i] - '0';

}

for (int i = 0; i<n1; i++) result += s1[i];


printf("#%d %d\n", t, result);

}


return 0;

}


'알고리즘 > SWEA' 카테고리의 다른 글

[SWEA 1244] 최대 상금  (0) 2018.08.13
[SWEA 1224] 계산기3  (0) 2018.08.10
[SWEA 1222] 계산기1  (0) 2018.08.10
[SWEA 1221] GNS  (0) 2018.08.10
[SWEA 1220] Magnetic  (0) 2018.08.10
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/10   »
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
글 보관함