码迷,mamicode.com
首页 > 其他好文 > 详细

TOJ--1507--大数乘法的初步实现

时间:2014-06-30 23:08:35      阅读:275      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   art   

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

一张桌子看来还真的很难入眠

好吧 这题真的做了好久 主要第一次接触 大数乘法

但我觉得这题应该是有规律的 就我现在还没找到

我想要是去打表一遍 应该会找到的 懒得去了

因为我的做法一般般吧 有疑问的只要去查下 大数乘法 的版本就好

虽然版本也有很多种 我的是理解起来最简单的吧 就模拟下

 

touch  me

 

直接上代码了额---------------下次 再也不那么水了

bubuko.com,布布扣
 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     else
30     {
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         else
59             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:

  人想要进行改变 实在太难了

  短暂的改变固然简单

  纠结了一下 算了 就当少赌球 请妹子次饭吧

 

 

 

 

 

TOJ--1507--大数乘法的初步实现,布布扣,bubuko.com

TOJ--1507--大数乘法的初步实现

标签:style   blog   http   color   os   art   

原文地址:http://www.cnblogs.com/radical/p/3815993.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!