與正確輸出不相符(line:25)
您的答案為: Uteba
正確答案為: Ezqlsukr
為什麼前面都對,到那裡會錯??
我的程式碼
#include <>
#include <>
#include <>
using namespace std ;
struct Atx
{
float value ;
int index ;
} ;
// 設定排序方式
bool leff(const Atx & m1, const Atx & m2)
{
return m1.value < m2.value ;
}
int main()
{
stringstream ss ;
int a ;
while( true )
{
cin >> a ;
if( a == 0 )
{
break ;
}
string left[a] , right[a] ;
Atx com[a] ;
for( int i = 0 ; i < a ; i ++ )
{
com[i].value = 0 ;
cin >> left[i] >> right[i] ;
com[i].value += atoi(right[i].substr(0,2).c_str())*3600 ;
com[i].value += atoi(right[i].substr(3,2).c_str())*60 ;
float x ;
x = atof(right[i].substr(6).c_str()) ;
com[i].value += x ;
com[i].index = i ;
}
sort( com , com + a , leff ) ;
int show = a / 3 ;
cout << "LIST START" << endl ;
for( int i = 0 ; i < show ; i ++ )
{
cout << left[com[i].index] << endl ;
}
//找尋一樣的值
for( int i = show ; i < a ; i ++ )
{
if( com[i].value == com[show-1].value )
{
cout << left[com[i].index] << endl ;
}
}
cout << "LIST END" << endl ;
}
}
哪一位好心人可以解決這問題 好像很多人都錯這裡
與正確輸出不相符(line:25)
您的答案為: Uteba
正確答案為: Ezqlsukr
為什麼前面都對,到那裡會錯??
我的程式碼
#include <>
#include <>
#include <>
using namespace std ;
struct Atx
{
float value ;
int index ;
} ;
// 設定排序方式
bool leff(const Atx & m1, const Atx & m2)
{
return m1.value < m2.value ;
}
int main()
{
stringstream ss ;
int a ;
while( true )
{
cin >> a ;
if( a == 0 )
{
break ;
}
string left[a] , right[a] ;
Atx com[a] ;
for( int i = 0 ; i < a ; i ++ )
{
com[i].value = 0 ;
cin >> left[i] >> right[i] ;
com[i].value += atoi(right[i].substr(0,2).c_str())*3600 ;
com[i].value += atoi(right[i].substr(3,2).c_str())*60 ;
float x ;
x = atof(right[i].substr(6).c_str()) ;
com[i].value += x ;
com[i].index = i ;
}
sort( com , com + a , leff ) ;
int show = a / 3 ;
cout << "LIST START" << endl ;
for( int i = 0 ; i < show ; i ++ )
{
cout << left[com[i].index] << endl ;
}
//找尋一樣的值
for( int i = show ; i < a ; i ++ )
{
if( com[i].value == com[show-1].value )
{
cout << left[com[i].index] << endl ;
}
}
cout << "LIST END" << endl ;
}
}
哪一位好心人可以解決這問題 好像很多人都錯這裡
與正確輸出不相符(line:429)
您的答案為: Zfb
正確答案為: Ixkvgpbmezkg
我是錯在這個怪地方
秒數用float進來之後*1000
這樣應該就不會有誤差了吧
然後我是用內建的sort函數去排struct
這樣會有跟氣泡排出來不一樣的結果嗎?
請高手解答一下