Project Euler Problem 08 C# Solution

原创 2017年01月03日 08:32:23

这道题目的难点在于怎么在 C# 中存储一个超级长的字符串,并且有 合适的 format,比如说 排版 和换行,目前已知的方式是 :null,只能写长长的一行,值得注意的是,如果在字符串前面加上 @ 符号,则可以输出双引号等奇怪符号 “”


答案记录如下:


using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;



namespace ProjectEuler01
{
    class Program
    {

       

        static void Main(string[] args)
        {
            Stopwatch watch = new Stopwatch();
            watch.Start();

            // Write your code here!  
            const String p = @"73167176531330624919225119674426574742355349194934969835203127745063262395783180169848018694788518438586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557668966489504452445231617318564030987111217223831136222989342338030813533627661428280644448664523874930358907296290491560440772390713810515859307960866701724271218839987979087922749219016997208880937766572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397536978179778461740649551492908625693219784686224828397224137565705605749026140797296865241453510047482166370484403199890008895243450658541227588666881164271714799244429282308634656748139191231628245861786645835912456652947654568284891288314260769004207198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450";



            int num_length = 13;
            long largest = 0;
           
            List<long> mynum = new List<long>();

            for (int i = 0; i < p.Length-num_length; i++)
            {
                long numm = 1;
                mynum.Clear();
                numm = p[i]-'0';
                mynum.Add(numm);
                
                for (int j = 1; j < num_length; j++)
                {
                    numm *= (p[i+j]-'0');
                    mynum.Add(p[i + j] - '0');
                }
                if (numm>largest)
                {
                    largest = numm;
                    mynum.ForEach(Console.WriteLine);
                    Console.WriteLine("=========================");
                }

            }
            Console.WriteLine(largest);
          

            watch.Stop();
            double ts = watch.Elapsed.TotalMilliseconds;
            Console.WriteLine("Totoal running time is " + ts + " ms ");
            Console.ReadLine();
        }

    }
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

相关文章推荐

Project Euler Question 07 C# Solution

这道问题是找到第10001个质数,我们解决这个问题需要注意的是: 1. 质数的定义是: 一个数n是质素,当且仅当 n 不能被2到 sqrt(n)之内的任意质数整除; 2. C# 有 return, b...

project euler problem 5

  • 2010-12-18 10:58
  • 18KB
  • 下载

Project Euler:Problem 49 Prime permutations

The arithmetic sequence, 1487, 4817, 8147, in which each of the terms increases by 3330, is unusual ...

Project Euler:Problem 22 Names scores

Using names.txt (right click and 'Save Link/Target As...'), a 46K text file containing over five-t...

Project Euler Problem 32 Pandigital products

Pandigital products Problem 32 We shall say that an n-digit number is pandigital if it makes use ...

Project Euler:Problem 51 Prime digit replacements

By replacing the 1st digit of the 2-digit number *3, it turns out that six of the nine possible valu...

Project Euler:Problem 86 Cuboid route

A spider, S, sits in one corner of a cuboid room, measuring 6 by 5 by 3, and a fly, F, sits in the o...

Project Euler:Problem 18 Maximum path sum I

By starting at the top of the triangle below and moving to adjacent numbers on the row below, the ma...

Project Euler - Problem 5

2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any rema...

Project Euler:Problem 50 Consecutive prime sum

The prime 41, can be written as the sum of six consecutive primes: 41 = 2 + 3 + 5 + 7 + 11 + 13 ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)