Created
June 22, 2013 09:15
-
-
Save ikautak/5840095 to your computer and use it in GitHub Desktop.
1から10の間に+ or -を入れて11を作る
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
// 符号と値を貰って足される数を返すわ | |
int calc( bool hugou, int num ) | |
{ | |
int ret = 0; | |
if( hugou ) | |
{ | |
ret = num; | |
} | |
else | |
{ | |
ret = (num * (-1)); | |
} | |
return ret; | |
} | |
int main() | |
{ | |
bool hugou[9]; | |
// 最初は全部- | |
for( int i = 0; i < 9; i++ ) | |
{ | |
hugou[i] = false; | |
} | |
int count = 0; | |
while( true ) | |
{ | |
int ans = 1; | |
// 現在の符号配列で合計を出す | |
for( int i = 2; i <= 10; i++ ) | |
{ | |
ans += calc( hugou[i-2], i ); | |
} | |
// 合計が11だったらログ吐く | |
if( ans == 11 ) | |
{ | |
cout << "HIT !!" << endl; | |
for( int i = 0; i < 9; i++ ) | |
{ | |
cout << i+1 << " "; | |
if( hugou[i] ) | |
{ | |
cout << "+"; | |
} | |
else | |
{ | |
cout << "-"; | |
} | |
cout << " "; | |
} | |
cout << "10 = 11" << endl; | |
} | |
++count; | |
for( int i = 0; i < 9; i++ ) | |
{ | |
hugou[i] = !(count & ( 1 << i )); | |
} | |
int end = 0; | |
for( int i = 0; i < 9; i++ ) | |
{ | |
end += hugou[i]; | |
} | |
if( end == 0 ) | |
{ | |
cout << count << endl; | |
cout << "end" << endl; | |
break; | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment