python-for-coding-test icon indicating copy to clipboard operation
python-for-coding-test copied to clipboard

p.313 문자열뒤집기 c++ 정답코드

Open ynsseon07 opened this issue 5 years ago • 0 comments

안녕하세요 문제를 보고 스스로 짰던 코드가 정답코드와 다르지만 맞게 동작하는건지 알고 싶어서 질문드립니다! `int main() { string s; cin >> s; int cnt = 0; int result = 0; for (int i = 0;i < s.length()-1;i++) { if (s[i] != s[i + 1]) cnt++; }

if (cnt % 2 == 0)
	result = cnt / 2;
else
	result = (cnt + 1) / 2;

cout << result << '\n';

}`

ynsseon07 avatar Dec 11 '20 05:12 ynsseon07