0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AtCoder Daily Training EASY 2024/12/31 - A (Pairing)

Posted at
use std::{collections::HashSet, io::{stdin, BufRead}};

fn main(){
    let std= stdin();
    let mut buf= std.lock().lines();
    let mut v: Vec<i32>= buf.next().unwrap().unwrap()
            .split_whitespace()
            .map(|f| f.parse::<i32>().unwrap() )
            .collect();

    let mut hashset:HashSet<i32>= HashSet::new(); 
    let mut cnt= 0;
    let v_cloned= v.clone();
    
    for e in v{
        let amount= v_cloned.iter().filter(|&n| *n == e).count();


        if amount > 3{
            cnt= 2;
            println!("{}", cnt);
            return;
        }

        if amount > 2{
            cnt= 1;
            println!("{}", cnt);
            return;
        }

        if hashset.contains(&e){
            cnt+=1;
        }
        hashset.insert(e);
    }

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

Source

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?