zoukankan      html  css  js  c++  java
  • TYVJ1000 A+B problem [存个高精模板]

    A+B Problem!

    通过模拟我故乡非洲的计算方式,我们很快可以解决这道题。

     1 #include<iostream>
     2 #include<cstdio>
     3 #include<cmath>
     4 int main(){
     5     int i,j;
     6     int a,b;
     7     scanf("%d%d",&a,&b);
     8     int sum=0;
     9     for(i=1;i<=a;i++)sum++;
    10     for(j=1;j<=b;j++)sum++;
    11     std::cout<<sum<<std::endl;
    12     return 0;
    13 }

    其实我就是想存个高精度模板

     1 struct num
     2 {
     3     int l,a[100];
     4     num operator + (const num &x) const
     5     {
     6         num ans;
     7         int len;
     8         memset(ans.a,0,sizeof(ans.a));
     9         for (int i=1;i<=l||i<=x.l;i++)
    10         {
    11             ans.a[i]+=a[i]+x.a[i];
    12             ans.a[i+1]+=ans.a[i]/10000;
    13             ans.a[i]%=10000;
    14         }
    15         if (l<x.l) len=x.l+1;
    16         else len=l+1;
    17         while (!ans.a[len]&&len) len--;
    18         ans.l=len;
    19         return ans;
    20     }
    21 }
     1 void prt(num x)
     2 {
     3     printf("%d",x.a[x.l]);
     4     for (int i=x.l-1;i>=1;i--)
     5     {
     6         int y=x.a[i];
     7         if (y<1000) printf("0");            
     8         if (y<100) printf("0");
     9         if (y<10) printf("0");
    10         printf("%d",y);
    11     }
    12 }
  • 相关阅读:
    github提交用户权限被拒
    vue数据响应式的一些注意点
    总结一下做移动端项目遇到的坑
    react-router
    promise-async-await
    递归函数
    Linux基础
    所有的数据处理都是map-reduce
    Mac下配置JAVA_HOME
    MySQL高级
  • 原文地址:https://www.cnblogs.com/SilverNebula/p/5644327.html
Copyright © 2011-2022 走看看