-2
我試圖解決這個任務:Sorting Numerical Data Alphabetically排序數值數據按字母順序
這裏是我的代碼
#include <iostream>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iterator>
#include <ostream>
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&a,const struct Int&b){
float s=0;
float t=0;
if ((count(a.x))==1 && (count(b.x))==1){
if (a.x<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<s){
return a.x;
}
return b.x;
}
if (b.x==1){
s=(float)a.x/(std::powf(10,count(a.x)-1));
if (s<b.x){
return a.x;
}
return b.x;
}
int n=count(a.x)<=count(b.x)?count(a.x):count(b.x);
for (int i=1;i<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<t)
return b.x;
}
return b.x;
}
int main(){
vector<Int>v(3);
for (int i=0;i<3;i++){
cin>>v[i].x;
}
std::sort(v.begin(),v.end(),Sort);
vector<Int>::iterator it;
for (int i=0;i<3;i++){
cout<<v[i].x<<endl;
}
return 0;
]
它編譯罰款,但是當我輸入數字就表明了我的異常完成它ubnormaly請告訴我爲什麼?
你在找什麼幫助?你不明白錯誤信息,或者相信他們是錯誤的,或者是什麼? – 2010-10-10 19:00:32
沒有錯誤,只有警告。請更準確地解釋你的問題。 – You 2010-10-10 19:09:31
我將更新我的代碼 – 2010-10-10 19:12:06