001
21.04.2003, 14:25 Uhr
virtual
Sexiest Bit alive (Operator)
|
Na, das war ja endlich mal was ulkiges
C++: |
#include <iostream> #include <string>
unsigned digits[] = { 1<<0, 1<<3, 1<<4, 1<<7, 1<<8, 1<<11, 1<<12};
int main() { std::string line;
for(;;) { unsigned long number;
std::cout<<"Bitte Zahl eingeben: "<<std::flush; std::getline(std::cin, line); if (1!=sscanf(line.c_str(), "%lu", &number)) { std::cerr<<"Fehlerhafte Eingabe - bitte nochmal!"<<std::endl; continue; } else if(0 == number) { std::cout <<"bye bye."<<std::endl; break; }
std::string str; for(int i=sizeof(digits)/sizeof(digits[0])-1; i>=0 && number!=0; --i) { if (number>=digits[i]) { for(int j=0; j<6 && number>=digits[ i]; ++j) { str += 'A'+i; number -= digits[ i]; } } else { unsigned long diff = digits[i]-number; for(int j=i-1; j>=0; --j) { if (digits[j]==number) { str += 'A'+j; number = 0; break; } else if (digits[j] == diff) { str += 'A'+j; str += 'A'+i; number -= digits[ i]-digits[j]; break; } } } }
std::cout<<str<<'('<<line<<')'<<std::endl; } }
|
-- Gruß, virtual Quote of the Month Ich eß' nur was ein Gesicht hat (Creme 21) |