Submission #2561348


Source Code Expand

use std::io::*;
fn main() {
    let s = read_v();
    let t: u8 = read();

    let mut mv = [0; 3];

    for c in s.iter() {
        match c {
            'R' => mv[0] += 1,
            'L' => mv[0] -= 1,
            'U' => mv[1] += 1,
            'D' => mv[1] -= 1,
            '?' => mv[2] += 1,
            _ => {}
        }
    }

    if mv[1] < 0 {
        mv[1] = mv[1];
    }
    if mv[0] < 0 {
        mv[0] = -mv[0];
    }

    let mut ans = 0;
    if t == 1 {
        ans = mv[0] + mv[1] + mv[2];
    } else {
        ans = mv[0] + mv[1] - mv[2];
    }

    println!("{}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let s = stdin();
    let b = s.bytes()
        .map(|b| b.unwrap() as char)
        .skip_while(|b| b.is_whitespace())
        .take_while(|b| !b.is_whitespace())
        .collect::<String>();
    b.parse::<T>().ok().unwrap()
}

fn read_v() -> Vec<char> {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect();
    b
}

// fn read_v<T: std::str::FromStr>() -> Vec<T> {
//     let mut s = String::new();
//     stdin().read_line(&mut s).expect("failed read_v");
//     s.trim()
//         .split_whitespace()
//         .map(|c| c.parse::<T>().ok().unwrap())
//         .collect::<Vec<T>>()
// }

Submission Info

Submission Time
Task B - ドローン
User celluloce
Language Rust (1.15.1)
Score 0
Code Size 1381 Byte
Status CE

Compile Error

error[E0308]: mismatched types
  --> ./Main.rs:10:13
   |
10 |             'R' => mv[0] += 1,
   |             ^^^ expected &char, found char
   |
   = note: expected type `&char`
   = note:    found type `char`

error[E0308]: mismatched types
  --> ./Main.rs:11:13
   |
11 |             'L' => mv[0] -= 1,
   |             ^^^ expected &char, found char
   |
   = note: expected type `&char`
   = note:    found type `char`

error[E0308]: mismatched types
  --> ./Main.rs:12:13
   |
12 |             'U' => mv[1] += 1,
   |             ^^^ expected &char, found char
   |
   = note: expected type `&char`
   = note:    found type `char`

error[E0308]: mismatched types
  --> ./Main.rs:13:13
   |
13 |             'D' => mv[1] -= 1,
   |             ^^^ expected &char, found char
   |
   = note: expected type `&char`
   = note:    found type `char`

error[E0308]: mismatched types
  --> ./Main.rs:14:13
   |
14 |             '?' => mv[2] += 1,
   |             ^^^ expected &char, found char
   |
   = note: expected ...