Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

AnEasyProblem/강성현

From ZeroWiki

Status

Problem 2453 User anoymity
Memory 736K Time 16MS
Language G++ Result Accepted

Idea

    • 1의 갯수를 구한뒤에 i를 하나씩 늘려가면서 1의 갯구를 비교

Source Code

#include <iostream>
using namespace std;

int main(void) {

	while (1) {
		int i, c = 0;
		cin >> i;
		if (i == 0) break;

		int temp = i;
		while (temp>0) { c+=temp%2; temp>>=1;}

		while (1) {
			int temp = ++i, cc = 0;
			while (temp>0) { cc+=temp%2; temp>>=1;}
			if (cc == c) break;
		}

		cout << i << endl;
	}
	return 0;
}

Trial and error

    • 처음엔 배열로 하려고 했다가 복잡한거같아서 걍 포기. 그냥 편하게 한것 같네요. 바로 accept 돼서 좀 놀람

ACM_ICPC/2011년스터디