Run ID 作者 问题 语言 测评结果 Time Memory 代码长度 提交时间
3405 吴奕希 书的价格 C++ Compile Error 0 MS 0 KB 491 2024-06-03 19:54:16

Tests(0/0):


Code:

# include<iostream> # include<algorithm> using namespace std; struct Book{ string name; double price; }books[10]; bool cmp(Book b1, Book b2){ return b1.price>b2.price; } int main(){ int n; cin>>n; for(int i = 0; i < n; i++){ getline(cin, books[i].name); cin>>books[i].price; } sort(books, books+n, cmp); printf("%.2lf,%c\n%.2lf,%c", books[0].price, books[0].name, books[n-1].price, books[n-1].name); return 0; }


Run Info:

Main.cc: In function 'int main()':
Main.cc:19:102: error: cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string}' through '...'
     printf("%.2lf,%c\n%.2lf,%c", books[0].price, books[0].name, books[n-1].price, books[n-1].name);
                                                                                                      ^
Main.cc:19:102: error: cannot pass objects of non-trivially-copyable type 'std::string {aka class std::basic_string}' through '...'
Main.cc:19:102: warning: format '%c' expects argument of type 'int', but argument 3 has type 'std::string {aka std::basic_string}' [-Wformat=]
Main.cc:19:102: warning: format '%c' expects argument of type 'int', but argument 5 has type 'std::string {aka std::basic_string}' [-Wformat=]