Codeforces 653A C#写算法题

前言

  • 就是想用c#实现一个网络流算法,但是怕有问题,又懒得手写测试(喂)。。。所以就想在codeforces上过点模板题试试。。
  • 但是从没有交过c#的题,这次就写个水题试一试。。感觉c#写题好麻烦。。

题意

  • 给你n个数,问你存在不存在3个连续的数

思路

  • hash一下,然后遍历所有hash值,连续3个不为0就yes

实现

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

namespace DTATest
{
    class Program
    {
        static List<int> array = new List<int>(1005);
        static void Main(string[] args)
        {
            for (int i = 0; i <= 1004; i++)
                array.Add(0);
            int n =Int32.Parse(Console.ReadLine());
            String str = Console.ReadLine();
            var input = str.Split(' ');
            foreach (var iter in input)
            {
                array[Int32.Parse(iter)]++;
            }
            bool flag = false;
            for (int i = 0; i < 1000;i++ )
            {
                if (array[i] > 0  && array[i + 1] > 0 && array[i + 2] > 0)
                {
                    Console.WriteLine("Yes");
                    flag = true;
                    break;
                }
            }
            if (!flag)
                Console.WriteLine("No");

            Console.Read();

        }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值