what is mistake?

it is problem:
Given a sequence of numbers. Need to streamline these numbers in non-decreasing in its last digit, and the last digit being equal - in non-decreasing numbers themselves.


Specifications
Input

The first line contains the number n ( 1 ≤ n ≤ 100 ), and the second - their own natural numbers not exceeding 32 000 .

Output

In the output file output sequence, ordered according to the condition.
Example
Example input
7
12 15 43 13 20 1 15
Example output
20 1 12 13 43 15 15


i tried to do it. it is my solution:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#include <iostream>
#include<cmath>
int main()
{
using namespace std;
int i,n,a[100], min, v, b,t[100],j,k;
cin>>n;
for(i=0;i<n;i++)
cin>>a[i];
for(i=0;i<n;i++)
t[k]=a[i]%10;
for(k=i;k<n;k++){
min=t[k];
v=k;
for (j=k; j<n; j++)
if (t[j] < min){
min = t[j];
v = j;}

b= t[k];
t[k] = min;
t[v] =b;
}
for(k=i;k<n;k++)
cout<<t[k]<<endl;

system("pause");
return 0;
}

P.S.it doesnt work....
Last edited on
use [ code] [ /code] tags around your code. And sorry, I didn't quite understand what exactly you need to do. Try to express it in mathematical terms if english is hard for you.
Last edited on
ok i did what you said,in this problem we write in order to increase of last digits
example
input
3
23 34 12 
output 
12 23 34

as you see last digits are increasing(2<3<4)
Look at that:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include<iostream>
using namespace std;
void quicksort(int v[100], int left, int right);
int v[100],q[100], x[100], n, i;
bool ok=false;
int main()
{
    cout<<"n=";
    cin>>n;
    for(i=1; i<=n; i++)
    {
        cout<<"v["<<i<<"]=";
        cin>>v[i];
    }
    for(i=1; i<=n; i++)
    {
        q[i]=v[i]%10;
    }
    quicksort(q, 1, n);
    for(i=1; i<=n; i++)
    {
        for(int j=1; j<=n; j++)
        {
            if((q[i]==(v[j]%10)))
            {
                x[i]=v[j];
                


            }
        }

    }

    for(i=1; i<=n; i++)
    {
        cout<<x[i]<<" ";
    }
}
void quicksort(int v[100], int left, int right)
{
    int i,j,mid,aux;
    i=left;
    j=right;
    mid=v[(left+right)/2];
    while(i<=j)
    {
        while(v[i]<mid)
        {
            i++;
        }
        while(mid<v[j])
        {
            j--;
        }
        if(i<=j)
        {
            aux=v[i];
            v[i]=v[j];
            v[j]=aux;
            i++;
            j--;

        }
    }
    if(left<j)
    {
        quicksort(v,  left, j);
    }
    if(right>i)
    {
        quicksort(v, i, right);
    }
}


This is a solution which works on numbers where the last figure is different. That means it works on your example not on the problem's example. Modify it and generalize it! Enjoy!
thank you very muchhhh!!!!!!!
Topic archived. No new replies allowed.