結果

問題 No.1617 Palindrome Removal
ユーザー silversmithsilversmith
提出日時 2021-07-26 00:45:38
言語 Rust
(1.72.1)
結果
AC  
実行時間 35 ms / 2,000 ms
コード長 1,111 bytes
コンパイル時間 2,360 ms
コンパイル使用メモリ 157,172 KB
実行使用メモリ 7,624 KB
最終ジャッジ日時 2023-09-28 14:36:44
合計ジャッジ時間 3,156 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
4,468 KB
testcase_01 AC 19 ms
4,572 KB
testcase_02 AC 33 ms
7,624 KB
testcase_03 AC 32 ms
5,884 KB
testcase_04 AC 35 ms
6,004 KB
testcase_05 AC 27 ms
4,944 KB
testcase_06 AC 5 ms
4,376 KB
testcase_07 AC 4 ms
4,376 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 1 ms
4,376 KB
testcase_10 AC 33 ms
6,016 KB
testcase_11 AC 16 ms
4,376 KB
testcase_12 AC 20 ms
4,676 KB
testcase_13 AC 20 ms
4,632 KB
testcase_14 AC 1 ms
4,380 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 1 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 1 ms
4,380 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,380 KB
testcase_23 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: variable `S` should have a snake case name
  --> 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
  --> 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
  --> 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`

warning: 3 warnings emitted

ソースコード

diff #

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);
		}
	}
}
0