001 : //========================================
002 : // program.c --- ACM ICPC 2012 Domestic B
003 : // Created by M.Miyazaki [2013.01.13]
004 : //========================================
005 :
006 : #include <stdio.h>
007 : #include <stdlib.h>
008 : #include <string.h>
009 :
010 : /**
011 : * 数値リストの最大要素数
012 : */
013 : #define MAX_ELEMENTS 21
014 :
015 : /**
016 : * 最大桁数
017 : */
018 : #define MAX_LENGTH 6
019 :
020 :
021 : int main(int argumentCount, char * argumentValues[])
022 : {
023 : int aValue;
024 : int numberOfDigit;
025 :
026 : scanf("%d %d", &aValue, &numberOfDigit);
027 :
028 : while (aValue != 0 || numberOfDigit != 0)
029 : {
030 : int valueArray[MAX_ELEMENTS];
031 : int count = 0;
032 : int maxNumber, minNumber;
033 : int indexOfDuplication;
034 :
035 : for (count = 0; count < MAX_ELEMENTS; count++)
036 : {
037 : valueArray[count] = -1;
038 : }
039 : count = 0;
040 : valueArray[count] = aValue;
041 :
042 : while (1)
043 : {
044 : int index;
045 : int index1, index2;
046 : char formatString[10];
047 : char valueString[MAX_LENGTH + 1];
048 :
049 : sprintf(formatString, "%%0%dd", numberOfDigit);
050 :
051 : sprintf(valueString, formatString, aValue);
052 : for (index = 0; index < strlen(valueString) - 1; index++)
053 : {
054 : if (valueString[index] < valueString[index + 1])
055 : {
056 : char temporaryCharacter;
057 : temporaryCharacter = valueString[index];
058 : valueString[index] = valueString[index + 1];
059 : valueString[index + 1] = temporaryCharacter;
060 : index = -1;
061 : }
062 : }
063 : maxNumber = atoi(valueString);
064 :
065 : sprintf(valueString, formatString, aValue);
066 : for (index = 0; index < strlen(valueString) - 1; index++)
067 : {
068 : if (valueString[index] > valueString[index + 1])
069 : {
070 : char temporaryCharacter;
071 : temporaryCharacter = valueString[index];
072 : valueString[index] = valueString[index + 1];
073 : valueString[index + 1] = temporaryCharacter;
074 : index = -1;
075 : }
076 : }
077 : minNumber = atoi(valueString);
078 :
079 : aValue = maxNumber - minNumber;
080 : count++;
081 : valueArray[count] = aValue;
082 :
083 : indexOfDuplication = -1;
084 :
085 : for (index1 = 0; index1 < count; index1++)
086 : {
087 : for (index2 = index1 + 1; index2 <= count; index2++)
088 : {
089 : if (valueArray[index1] == valueArray[index2])
090 : {
091 : indexOfDuplication = index1;
092 : index1 = MAX_ELEMENTS;
093 : index2 = MAX_ELEMENTS;
094 : }
095 : }
096 : }
097 :
098 : if (indexOfDuplication != -1)
099 : {
100 : printf("%d ", indexOfDuplication);
101 : printf("%d ", valueArray[indexOfDuplication]);
102 : printf("%d\n", count - indexOfDuplication);
103 : break;
104 : }
105 : }
106 :
107 : scanf("%d %d", &aValue, &numberOfDigit);
108 : }
109 :
110 : return EXIT_SUCCESS;
111 : }
112 :
This document was generated by NanigashiBiyori on 2013/01/15 at 21:38:14.