文章

8

粉丝

0

获赞

17

访问

2.9k

头像
数字排序 题解:stod(s)函数转换之后的小数和字符串不一致会报错50%
P1966 华东师范大学2023年机试
发布于2025年3月16日 20:04
阅读数 275

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
struct node{
   double a;
   string s;
};
bool com(node a,node b)
{
    return a.a<b.a;
}
int main() {
    int n;
   node p[10000];
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> p[i].s;
        p[i].a = stod(p[i].s); 
    }
    sort(p, p + n,com);
    for (int i = 0; i < n; i++) {
        cout << p[i].s << endl;
    }
    return 0;
}

 

stod(s)函数转换之后的小数和字符串不一致会报错50%

 

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发