結果
| 問題 |
No.5 数字のブロック
|
| ユーザー |
tsubu_taiyaki
|
| 提出日時 | 2017-02-04 08:13:30 |
| 言語 | Rust (1.83.0 + proconio) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,207 bytes |
| コンパイル時間 | 12,686 ms |
| コンパイル使用メモリ | 387,304 KB |
| 最終ジャッジ日時 | 2024-11-14 19:56:53 |
| 合計ジャッジ時間 | 13,397 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
error[E0782]: trait objects must include the `dyn` keyword
--> src/main.rs:9:21
|
9 | tokens: &'a mut Iterator<Item = String>,
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
9 | tokens: &'a mut dyn Iterator<Item = String>,
| +++
error[E0782]: trait objects must include the `dyn` keyword
--> src/main.rs:13:23
|
13 | fn new(i: &'a mut Iterator<Item = String>) -> Self {
| ^^^^^^^^^^^^^^^^^^^^^^^
|
help: add `dyn` keyword before this trait
|
13 | fn new(i: &'a mut dyn Iterator<Item = String>) -> Self {
| +++
For more information about this error, try `rustc --explain E0782`.
error: could not compile `main` (bin "main") due to 2 previous errors
ソースコード
#![allow(unused_imports)]
use std::io::{self, BufRead};
use std::str::FromStr;
use std::collections::*;
use std::cmp::*;
struct Parser<'a> {
tokens: &'a mut Iterator<Item = String>,
}
impl<'a> Parser<'a> {
fn new(i: &'a mut Iterator<Item = String>) -> Self {
Parser {tokens: i}
}
fn take<T: FromStr>(&mut self) -> T {
match self.tokens.next().expect("empty iterator").parse() {
Ok(x) => x,
Err(_) => panic!()
}
}
fn take_some<T: FromStr>(&mut self, n: usize) -> Vec<T> {
self.tokens.take(n).map(|s| match s.parse() { Ok(x) => x, Err(_) => panic!() } ).collect()
}
}
fn main() {
let stdin = io::stdin();
let mut tokens = stdin.lock().lines().filter_map(|x| x.ok()).flat_map(|x| x.split_whitespace().map(|s| s.to_owned()).collect::<Vec<String>>());
let mut parser = Parser::new(&mut tokens);
let l: i64 = parser.take();
let n: i64 = parser.take();
let mut w: Vec<i64> = parser.take_some(n as usize);
w.sort();
let w = w;
let mut s = 0i64;
let mut ans = 0;
for wi in w {
s += wi;
if s <= l {
ans += 1;
}
}
println!("{}", ans);
}
tsubu_taiyaki