TOJ--1507--大數乘法的初步實現

來源:互聯網
上載者:User

標籤:style   blog   http   color   os   art   

Ah 我看來需要重新評估下自己的睡眠要求了 =-=

一張桌子看來還真的很難入眠

好吧 這題真的做了好久 主要第一次接觸 大數乘法

但我覺得這題應該是有規律的 就我現在還沒找到

我想要是去打表一遍 應該會找到的 懶得去了

因為我的做法一般般吧 有疑問的只要去查下 大數乘法 的版本就好

雖然版本也有很多種 我的是理解起來最簡單的吧 就類比下

 

touch  me

 

直接上代碼了額---------------下次 再也不那麼水了

 1 // 尋找7  2 #include <iostream> 3 #include <cstring> 4 using namespace std; 5  6 int k , m; 7 const int size = 1010; 8 int ch[3]; 9 int temp[size];10 int str[size];11 12 void multiply()13 {14     int len , t , x;15     memset( temp , 0 , sizeof(temp) );16     if(m<10)17     {18         ch[0] = m;19         ch[1] = ch[2] = 0;20         x = 1;21     }22     else if(m>=10&&m<100)23     {24         ch[0] = m/10;25         ch[1] = m%10;26         ch[2] = 0;27         x = 2;28     }29     else30     {31         ch[0] = m/100;32         ch[1] = (m%100)/10;33         ch[2] = (m%100)%10; 34         x = 3;35     }36     temp[0] = 1;37     len = 1;38     for( int n = 1 ; ; n++ )39     {40         memset( str , 0 , sizeof(str) );41         for( int i = 0 ; i<x ; i++ )42         {43             for( int j = 0 ; j<len ; j++ )44             {45                 str[i+j+1]+=ch[i]*temp[j];46             }47         }48         for( int i = x+len-1 ; i>=1 ; i-- )49         {50             if( str[i]>=10 )51             {52                 str[i-1]+=str[i]/10;53                 str[i]%=10;54             }55         }56         if( str[0]!=0 )57             t = 0;58         else59             t = 1;60         int tt = t;61         for( int j = 0 ; t<x+len ; t++ , j++ )62         {63             temp[j] = str[t];64         }65         if( str[x+len-k]==7 )66         {67             cout<<n<<endl;68             break;69         }70         len+=x-tt;71     }72 }73 74 int main()75 {76     while(cin>>k>>m)77     {78         multiply();79     }    80     return 0;81 }
View Code

 

today:

  人想要進行改變 實在太難了

  短暫的改變固然簡單

  糾結了一下 算了 就當少賭球 請妹子次飯吧

 

 

 

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.