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?

paiza.ioでc# その12

Last updated at Posted at 2024-11-14

概要

paiza.ioでc#、やってみた。
練習問題やってみた。

練習問題

AtCoderをhashsetを使って解け。

参考にしたページ

サンプルコード

abc278 c

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Numerics;

public class Hello
{
    public static void Main() {
        var NQ = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var N = NQ[0];
        var Q = NQ[1];
        var users = new Dictionary<int, HashSet<int>>();
        for (int i = 0; i <= Q - 1; i++) 
        {
            var op = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            if (op[0] == 1) 
            {
                if (users.ContainsKey(op[1]) == false) 
                {
                    users.Add(op[1], new HashSet<int>() { op[2] });
                }
                else 
                {
                    users[op[1]].Add(op[2]);
                }
            }
            else if (op[0] == 2) 
            {
                if (users.ContainsKey(op[1]) == false) 
                {
                    users.Add(op[1], new HashSet<int>());
                }
                else 
                {
                    users[op[1]].Remove(op[2]);
                }
            }
            else 
            {
                if (users.ContainsKey(op[1]) && users.ContainsKey(op[2])) 
                {
                    if (users[op[1]].Contains(op[2]) && users[op[2]].Contains(op[1])) 
                    {
                        Console.WriteLine("Yes");
                    }
                    else 
                    {
                        Console.WriteLine("No");
                    }
                }
                else 
                {
                    Console.WriteLine("No");
                }
            }
        }
    }
}

実行結果

No
Yes
No
No

成果物

以上

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?