现在的位置: 首页 > 综合 > 正文

1381. a*b

2019年11月11日 ⁄ 综合 ⁄ 共 377字 ⁄ 字号 评论关闭

很早前做的高精度,贴上来

#include<iostream>
#include<cstring>
using namespace std;
int main()
{
  int t;
  cin >> t;
  while(t--)
  {
    string s;
    int  b;
   cin >> s >> b;
   if(b==0)
   {
   cout << 0 << endl; 
   continue;
   }
   int a[10000] = {0};
   int h = s.length();
   for(int i = 0; i < h; i ++)
    a[i] = s[h-i-1] - '0';  
   for(int i = 0; i < h; i++) 
      a[i] *= b;
    for(int i = 0; i < h; i++) 
      if(a[i]>=10)
      {
      a[i+1] += a[i]/10;
      a[i] %= 10;   
      }
    
    if(a[h] != 0) cout << a[h];
     for(int i = 0; i < h; i++)
     cout << a[h-i-1];
     cout << endl;
  }
  
    
}                                 

抱歉!评论已关闭.