[Project Euler]加入歐拉 Problem 8

來源:互聯網
上載者:User

Find the greatest product of five consecutive digits in the 1000-digit number.

73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
24219022671055626321111109370544217506941658960408
07198403850962455444362981230987879927244284909188
84580156166097919133875499200524063689912560717606
05886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450

 

在1000個數字裡面找出連續5個相乘最大的數。同時返回乘積

 

注意一點C語言裡面的續行符號 是用\加空格共同組成的,所以一定要注意檢查轉換過程中的space符號。

*p – 48 這裡 48的ASCII 就是 ‘0’,相減就可以得到對應字元的整數。

 

這個沒什麼演算法很簡單:

歐拉項目第八題#include <stdio.h>#include <stdlib.h>int main(int argc, char *argv[]){    char *p = "73167176531330624919225119674426574742355349194934\                96983520312774506326239578318016984801869478851843\                85861560789112949495459501737958331952853208805511\                12540698747158523863050715693290963295227443043557\                66896648950445244523161731856403098711121722383113\                62229893423380308135336276614282806444486645238749\                30358907296290491560440772390713810515859307960866\                70172427121883998797908792274921901699720888093776\                65727333001053367881220235421809751254540594752243\                52584907711670556013604839586446706324415722155397\                53697817977846174064955149290862569321978468622482\                83972241375657056057490261407972968652414535100474\                82166370484403199890008895243450658541227588666881\                16427171479924442928230863465674813919123162824586\                17866458359124566529476545682848912883142607690042\                24219022671055626321111109370544217506941658960408\                07198403850962455444362981230987879927244284909188\                84580156166097919133875499200524063689912560717606\                05886116467109405077541002256983155200055935729725\                71636269561882670428252483600823257530420752963450";                    int arr[1000]; // 轉換成整形數組來處理     int i = 0;    while(*p != '\0')    {        if(*p != 32) // 處理*p是不是換行中的space符         {            arr[i] = *p - 48;            i++;                    }                p++;           }        int max = 0;    for(i = 0; i < 996; i++)    {        int tmp = arr[i] * arr[i + 1] * arr[i + 2] * arr[i + 3] * arr[i + 4];        if(tmp > max)                max = tmp;                }        printf("%d", max);    system("PAUSE");  return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.