U E D R , A S I H C RSS

An Easy Problem/강성현

Status

Problem 2453Useranoymity
Memory736KTime16MS
LanguageG++ResultAccepted

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 돼서 좀 놀람

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:27
Processing time 0.0098 sec