U E D R , A S I H C RSS

An Easy Problem/권순의

Source

#include <IOStream>
#include <cmath>

using namespace std;

int main()
{
	int getNum = -1;
	int getBinary[21];
	int min = 0;
	int output = 0;

	while(getNum != 0)
	{
		cin >> getNum;

		for(int i = 0; i < 21; i++)
		{
			getBinary[i] = 0;
		}

		if((getNum > 0) && (getNum <= 1000000))
		{
			for(int i = 0; i < 21; i++)
			{				
				getBinary[i] = getNum % 2;
				getNum /= 2;
				cout << getBinary[i];
			}

			cout << endl;

			getNum = 1;

			for(int i = 0; i < 21; i++)
			{
				if(getBinary[i] == 1)
				{
					if(getBinary[i + 1] == 0)
					{
						getBinary[i + 1] = 1;
						getBinary[i] = 0;
						i++;
					}else{
						getBinary[i] = 0;
						getBinary[min++] = 1;
					}
				}

				cout << getBinary[i];
						
				output += (int)(getBinary[i] * pow(2.0, i));
			}
			
			cout << endl << output << endl;
		}else if(getNum == 0){
			break;
		}else{
			cout << "잘못된 입력입니다." << endl;
			break;
		}
	}

	return 0;
}

* 그냥 아무 생각 없이 하다가 망쳤네요 -_-;; 어디선가 꼬여버렸고 ㄷㄷㄷ 아놔 - 권순의
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2013-11-16 02:06:51
Processing time 0.0902 sec