[백준/BOJ] 12927. 배수 스위치 [Silver 4]

jychan99·2021년 9월 27일
0
post-thumbnail
  1. 배수 스위치

문제 출처 : https://www.acmicpc.net/problem/12927

배열의 인덱스만 신경써주고 천천히 차례차례생각하다보면 그리 어려운 문제는 아니였다.

code

#include <stdio.h>
#include <string.h>
int main()
{
	char light[1000] = { 0 };
	int len, i, j, cnt = 0;
	scanf("%s", light);
	len = strlen(light);
	for (i = 0; i < len; i++)
	{
		if (light[i] == 'Y')
		{
			for (j = i; j < len; j += i+1)
			{
				if (light[j] == 'Y')
					light[j] = 'N';
				else
					light[j] = 'Y';
			}
			cnt++;
		}
	}
	printf("%d", cnt);
	return 0;
}
profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐥

0개의 댓글