Sorting Numerical Data Alphabetically
<p>i am trying to solve this task: <a href="http://stackoverflow.com/questions/719614/sorting-numerical-data-alphabetically">http://stackoverflow.com/questions/719614/sorting-numerical-data-alphabetically</a></p>

<p>here is my code</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;math.h&gt;
#include &lt;vector&gt;
#include &lt;algorithm&gt;
#include &lt;iterator&gt;
#include &lt;ostream&gt;
using namespace std;
float count(int  n) {
    float total=0;
    while (n!=0) {
        n/=10;
        total++;
    }
    return total;
}

struct Int {
    int x;
};

int Sort(const struct Int&amp;a,const struct Int&amp;b){
    float s=0;
    float t=0;
    if ((count(a.x))==1 &amp;&amp; (count(b.x))==1){
        if (a.x&lt;b.x){
            return a.x;
        }
        return b.x;
    }

    if ((count(a.x))==1){
        s=(float)b.x/(std::powf(10,(count(b.x)-1)));
        if (a.x&lt;s){
           return a.x;
        }
        return b.x;
    }

    if ( b.x==1){
       s=(float)a.x/(std::powf(10,count(a.x)-1));
       if (s&lt;b.x){
           return a.x;
       }
       return b.x;
    }
    int n=count(a.x)&lt;=count(b.x)?count(a.x):count(b.x);
    for (int i=1;i&lt;n;i++){
       s=(float)a.x/(std::powf(10,count(a.x)-i));
       t=(float)b.x/(std::powf(10,count(b.x)-i));

       if (s&lt;t)
           return b.x;
    }
    return b.x;
}

int main(){

    vector&lt;Int&gt;v(3);
    for (int i=0;i&lt;3;i++){
        cin&gt;&gt;v[i].x;
    }
    std::sort(v.begin(),v.end(),Sort);
    vector&lt;Int&gt;::iterator it;
    for (int i=0;i&lt;3;i++){

       cout&lt;&lt;v[i].x&lt;&lt;endl;
    }
    return 0;
]
</code></pre>

<p>it compiles fine but when i enter numbers it showed me  exceptions it finished ubnormaly please tell me why?</p>
