Study/C++ 6174 코딩하는 야구쟁이 2011. 9. 29. 20:43 #include using namespace std; void main() { char input[4]; int temp=0; int i,j; int max_number=0; int min_number=0; int result=0; int count=0; for(i=0;i<4;i++) { cin>>input[i]; } while(result != 6174) { for(i=0;i<4;i++) { for(j=i;j<4;j++) { if(input[i] < input[j]) { temp = input[i]; input[i] = input[j]; input[j] = temp; } max_number = (int)input[0] * 1000 + (int)input[1] * 100 + (int)input[2] * 10 + (int)input[3]; if(input[i] > input[j]) { temp = input[i]; input[i] = input[j]; input[j] = temp; } min_number = (int)input[3] * 1000 + (int)input[2] * 100 + (int)input[1] * 10 + (int)input[0]; result = (min_number)-(max_number); } } cout << min_number << " - " << max_number << " = " << result << endl; int temp = result; for(int i=0; i<4; i++) { input[i] = temp % 10; temp /= 10; } } }