CS/알고리즘

[알고리즘] 점수 계산

hojak99 2016. 12. 1. 19:25

'o'와 'x' 표시를 해서 점수를 매기는데 여기서 점수는 'o'가 누적되는 방식으로 채점된다. 자신을 포함한 연속된 'o'의 개수만큼 점수로 채점.


Ex) oooxoo 일 때 1+2+3+0+1+2 = 9


#include <stdio.h>

#include<string.h>

#include <malloc.h>


int main()

{

char arr[100];

int cnt = 1;

int sum = 0;

scanf("%s", arr);


int aaa= strlen(arr);

int *arrSize = (int*)malloc(sizeof(int)*aaa);


for (int i = 0; i < strlen(arr); i++) {

if (arr[i] == 'o') {

sum += cnt;

cnt += 1;

continue;

}

else if (arr[i] == 'x') {

cnt = 1;

continue;

}


}


printf("%d", sum);

}


출력값 :

(입력) ooxxoxxooo

10


반응형