인프런 커뮤니티 질문&답변
2-m 질문
작성
·
342
0
https://www.acmicpc.net/source/share/17181f173abb44ba956ed80b9146d5fb
저는 처음에 vcnt라는 변수를 놔두어서 '6'이 올 때마다 1씩 증가시켜서 3을 찾는 식으로 하였는데 왜 틀렸는지 알 수 있을 까요??
답변 1
0
큰돌
지식공유자
안녕하세요 ㅎㅎ
주석달았는데 참고 부탁드립니다.
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define endl "\n"
int n, v = 666;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n;
int cnt = 0, val = 0;
// 왠 cnt != n ??
// N번째 영화의 제목에 들어간 숫자를 출력하는 거기 때문에. vcnt가 3일 때 th++하고 th가 n일 때
// 그 th를 출력하면 되는거 아닌가요?
while (cnt != n)
{
string tmp = to_string(v);
int vcnt = 0, th = 0;
for (int i = 0; i < tmp.size(); ++i)
{
if (tmp[i] == '6') ++vcnt;
else vcnt = 0;
if (vcnt == 3)
{
++th; vcnt = 0;
//break;를 걸어줘야 되는 거 아닌가요?
}
}
if (th > 1) th = 0;
else if (th == 1)
{
th = 0;
++cnt;
val = v;
}
++v;
}
cout << val << endl;
return 0;
}





그리고 endl은 쓰지 말아야 합니다. 교안 참고 부탁드립니다.