zoukankan      html  css  js  c++  java
  • TOJ--1507--大数乘法的初步实现

    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     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:

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

      短暂的改变固然简单

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

    just follow your heart
  • 相关阅读:
    指针系统学习5-对使用字符指针变量和字符数组的讨论
    指针系统学习4-字符串与指针
    指针系统学习3-多维数组与指针
    指针系统学习2
    指针系统学习1
    你视为意见领袖的大 V,可能只是个僵尸号
    phpinfo()
    用shell脚本守护后台进程
    mysql命令(command)
    MySQL数据库视图(view),视图定义、创建视图、修改视图
  • 原文地址:https://www.cnblogs.com/radical/p/3815993.html
Copyright © 2011-2022 走看看