Giter Site home page Giter Site logo

rust_atcoder's Introduction

RustでAtCoder

使い方

  • コンテストを追加
    • cargo compete new ${contest_name} でコンテストを追加
  • テスト
    • cd ${contest_name}
    • cargo compete test ${problem_num}

入力の受け取り

基本

input! {
    n: usize,
    mut m: usize,  // 変更可能にする
}

配列の入力

input! {
    n: usize,
    mut m: usize,
    v: [usize; n], // 長さnのusizeの配列
    a: [[i32; n]; m] // `a` is Vec<Vec<i32>>, (m, n)-matrix.
}

文字列の入力

use proconio::input;
use proconio::marker::{Bytes, Chars};

input! {
    string: String, // read as String
    chars: Chars,   // read as Vec<char>
    bytes: Bytes,   // read as Vec<u8>
}

// if you enter "string chars bytes" to the stdin, they are like this.
assert_eq!(string, "string");
assert_eq!(chars, ['c', 'h', 'a', 'r', 's']);
assert_eq!(bytes, b"bytes");

グラフ系

use proconio::input;
use proconio::marker::Usize1;

input! {
    n: usize,
    edges: [(Usize1, Usize1); n], // Usize1にすると1-index
}

// if you enter "4   1 3   3 4   6 1   5 3", the decremented value is stored.
assert_eq!(edges[0], (0, 2));
assert_eq!(edges[1], (2, 3));
assert_eq!(edges[2], (5, 0));
assert_eq!(edges[3], (4, 2));

基本の型

文字(char)

  • chars()とかで文字のiter作れる

連結

  • vec![‘a’,’i’].into_iter().collect::<String>(); で行ける
    • charを連結したものがStringだから。

文字列

String -> &str

let str1: String = String::from("abc");
let str2: &str = &str1;
println!("{}", str2);  // "abc"

&str -> String

let str1: &str = "abc";
let str2: String = str1.to_string();
println!("{}", str2);  // "abc"

Vector・配列

初期化

  • とりあえず初期化: let mut vec = Vec::<T>new();
  • 指定した値で初期化: let mut vec = vec![1, 2, 3];
  • 空で初期化: let mut vec = vec![];
  • 値を繰り返し使って初期化: let mut vec = vec![0;5];

追加

vec.push(x)で追加できる

ソート

mutにしておいた上でvec.sort()でいける

含まれるか?

["aaa","iii"].contains(“aaa”);でいける

最大/最小

vec.iter().min().unwrap()で取れる

データ構造

処理

Rustの実行

リンク

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.