結果
問題 |
No.1617 Palindrome Removal
|
ユーザー |
![]() |
提出日時 | 2021-07-26 00:45:38 |
言語 | Rust (1.83.0 + proconio) |
結果 |
AC
|
実行時間 | 37 ms / 2,000 ms |
コード長 | 1,111 bytes |
コンパイル時間 | 23,963 ms |
コンパイル使用メモリ | 378,896 KB |
実行使用メモリ | 6,016 KB |
最終ジャッジ日時 | 2024-07-21 09:17:52 |
合計ジャッジ時間 | 17,079 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 20 |
コンパイルメッセージ
warning: variable `S` should have a snake case name --> src/main.rs:11:6 | 11 | let S=getline(); | ^ help: convert the identifier to snake case (notice the capitalization): `s` | = note: `#[warn(non_snake_case)]` on by default warning: variable `S` should have a snake case name --> src/main.rs:12:6 | 12 | let S=S.trim(); | ^ help: convert the identifier to snake case (notice the capitalization): `s` warning: variable `mS` should have a snake case name --> src/main.rs:51:7 | 51 | let mS = format!("{}{}", &S[..S.len()/2], &S[S.len()/2+2..]); | ^^ help: convert the identifier to snake case: `m_s`
ソースコード
use std::collections::HashSet; use std::process; fn getline() -> String{ let mut __ret=String::new(); std::io::stdin().read_line(&mut __ret).ok(); return __ret; } fn main() { let S=getline(); let S=S.trim(); if S.len() == 1 { print!("{}", -1); process::exit(0); } let rev:String = S.chars().rev().collect(); if S != rev { print!("{}", S.len()); process::exit(0); } if S.len() == 2 { print!("{}", 0); process::exit(0); } if S.len() == 3 { print!("{}", -1); process::exit(0); } let char_set: HashSet<_> = S.chars().collect(); let char_num = char_set.len(); if char_num == 1 { if S.len() % 2 == 0 { print!("{}", 0); process::exit(0); }else { print!("{}", -1); process::exit(0); } } if S.len() % 2 == 0 { print!("{}", S.len() -2); process::exit(0); }else { let mS = format!("{}{}", &S[..S.len()/2], &S[S.len()/2+2..]); let m_char_set: HashSet<_> = mS.chars().collect(); let m_char_num = m_char_set.len(); if m_char_num == 1 { print!("{}", S.len() -2); process::exit(0); }else { print!("{}", S.len() -2); process::exit(0); } } }