λͺ©λ‘μœΌλ‘œ
λ°±μ€€

BOJ - [Basic Algebra - 2506 μ μˆ˜κ³„μ‚°] - Bronze III πŸ₯‰

https://www.acmicpc.net/problem/2506 λ°”λ‘œ μ „λ¬Έμ œμ™€ μœ μ‚¬ν•˜κ²Œ 배열을 κ²€μ‚¬ν•˜λ©΄μ„œ λ°°μ—΄μ˜ i 와 i-1 자리λ₯Ό λΉ„κ΅ν•˜μ—¬ 1 이 μ—°μ†λ˜λŠ”μ§€λ₯Ό κ³ λ €ν•˜μ—¬ μ μˆ˜μ— 가산점이 λΆ™λ„λ‘ν•˜μ—¬ μ΅œμ’…μ μœΌλ‘œ 점수λ₯Ό μ‚°μΆœν•˜λ©΄ λ˜λŠ” 것 μ΄μ—ˆλ‹€. λͺ‡λ²ˆ μ—°μ†λ˜λŠ”μ§€λŠ” combo λ³€μˆ˜λ₯Ό ...

1λΆ„ 읽기

문제

https://www.acmicpc.net/problem/2506

μ„€λͺ…

λ°”λ‘œ μ „λ¬Έμ œμ™€ μœ μ‚¬ν•˜κ²Œ 배열을 κ²€μ‚¬ν•˜λ©΄μ„œ λ°°μ—΄μ˜ i 와 i-1 자리λ₯Ό λΉ„κ΅ν•˜μ—¬ 1 이 μ—°μ†λ˜λŠ”μ§€λ₯Ό κ³ λ €ν•˜μ—¬ μ μˆ˜μ— 가산점이 λΆ™λ„λ‘ν•˜μ—¬ μ΅œμ’…μ μœΌλ‘œ 점수λ₯Ό μ‚°μΆœν•˜λ©΄ λ˜λŠ” 것 μ΄μ—ˆλ‹€. λͺ‡λ²ˆ μ—°μ†λ˜λŠ”μ§€λŠ” combo λ³€μˆ˜λ₯Ό ν†΅ν•΄μ„œ 세도둝 ν•˜μ˜€κ³ , μ΅œμ’…μ μœΌλ‘œ μ μˆ˜λŠ” score λ³€μˆ˜μ— λͺ¨μ΄λ„둝 ν•˜μ˜€λ‹€. 또 μ†ŒμŠ€μ˜ 주석을 보면 μ•Œκ² μ§€λ§Œ i κ°€ 0 μΌλ•ŒλŠ” μ•žλ°°μ—΄μ΄ μ—†μ–΄ 비ꡐ할 λŒ€μƒμ΄ μ—†μœΌλ―€λ‘œ λ³„λ„λ‘œ λ”°λ‘œ 검사λ₯Ό ν•΄ 점수λ₯Ό νŒμ •ν•˜λ„λ‘ ν•˜μ˜€λ‹€.

μ½”λ“œ

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main()
{
	int n,array[100],score=0,combo=0;
	scanf("%d",&n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &array[i]);
		if (i != 0)
		{
			if (array[i - 1] == 1 && array[i] == 1)
			{
				score += (combo + 1);
				combo++;
			}
			else if (array[i] == 1)
			{
				score++;
				combo++;
			}
			else
				combo = 0;


		}
		else if (array[i] == 1)
		{
			score++;
			combo++;
		}	
	}
	printf("%d", score);
	
	return 0;
}

λŒ“κΈ€