qq_39552268 于 2017.09.13 21:56 提问

void main()
{
int inputNumber;

``````    int a[] = { 70,32,40,12,85,23,901,100,75,60 };
int len = sizeof(a) / sizeof(a[0]);
for (int i = 0; i < len; i++)
{
cout << a[i] << " ";
}

}
int maxbit(int a[], int len)//最大是几位数
{
int d = 1;
for (int i = 0; i < len; i++)
{
int c = 1;
int p = a[i];
while (p / 10)
{
p = p / 10;
c++;
}
if (c > d)
{
d = c;
}
}

return d;

}
{

int temp[10];
int count[10];
int r = 1;
int d = maxbit(a, len);

for (int i = 1; i <= d; i++)
{
for (int i = 0; i < 10; i++)//装桶前先清桶
{
count[i] = 0;
}
for (int i = 0; i < 10; i++)
{
int k = a[i] / r;
int q = k % 10;
count[q]++;

}
for (int i = 1; i < 10; i++)//计算位置
{
count[i] += count[i - 1];
}

**for (int j = len-1; j>=0; j--)
{
int k = a[j] / r;
int q = k % 10;
temp[count[q] - 1] = a[j];
count[q]--;
}**
for (int i = 0; i < len; i++)

{
a[i] = temp[i];
}
r = r * 10;
}

}
``````

for (int j = 0; j<len; j++)
{
int k = a[j] / r;
int q = k % 10;
temp[count[q] - 1] = a[j];
count[q]--;
}

for (int j = 0; j<len; j++)
{
int k = a[j] / r;
int q = k % 10;
temp[count[q] - 1] = a[j];
count[q]--;
}

2个回答

m0_38124502   2017.09.14 12:12

qq_39552268 。。。不好意思 for (int j = len-1; j>=0; j--) { int k = a[j] / r; int q = k % 10; temp[count[q] - 1] = a[j]; count[q]--; }**
4 个月之前 回复
qq_39552268   2017.09.17 22:43

for (int j = len-1; j>=0; j--)
{
int k = a[j] / r;
int q = k % 10;
temp[count[q] - 1] = a[j];
count[q]--;
}

for (int j = 0; j<len; j++)
{
int k = a[j] / r;
int q = k % 10;
temp[count[q] - 1] = a[j];
count[q]--;
}