高精50分,Dalao们有没有知道怎么办的

P1001 A+B Problem

Poombom @ 2023-07-01 08:58:27

本来是写完P1303回来逝逝的,结果50分...... 在P1303都AC了 代码:

#include<bits/stdc++.h>
using namespace std;
int a[1000001]={},b[1000001]={},c[1000001]={},i,f;
char d[1000001],e[1000001];
bool x=false;
int main( )
{
    cin>>d>>e;
    a[0]=strlen(d);
    b[0]=strlen(e);
    for(i=1;i<=a[0];i++)a[i]=d[a[0]-i]-'0';
    for(i=1;i<=b[0];i++)b[i]=e[b[0]-i]-'0';
    f=max(a[0],b[0]);
    for(i=1;i<f+1;i++)
    {
        c[i]=a[i]+b[i];
        if(c[i]>=10){c[i]%=10;b[i+1]++;}
    }
    c[i]=b[i];
    if(c[i] != 0)cout<<c[i];
    c[0]=i;
    for(int i=c[0]-1; i>=1; i--) {
        cout<<c[i];
    }
    return 0;
}

敲了有一个小时才敲出来的 可能我还是太菜了


by yinminghao @ 2023-07-21 21:25:33

干嘛写的那么复杂


#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a;
    cin>>a;
    int b;
    cin>>b;
    cout<<(a*b)<<;
    return 0; 
 }

by Jaspeter @ 2023-07-22 18:02:31

#include<bits/stdc++.h>
#define action void
#define core int main()
#define _  
#define print printf
#define memory 
using namespace std;
const int maxn = 1000;
struct bign
{
    int len, s[maxn];
    bool fh=1;
    void clean() {while(len > 1 && s[len-1 ]==0) len--;}
    bign() { memset(s, 0, sizeof(s)); len = 1; }
    bign operator =(const char* num)
    {
        int ii=0;
        memset(s, 0, sizeof(s));
        len = strlen(num);
        if (num[0]=='-')
        {
            ii=1;
        } 
        for (int i=0; i < len-ii; i++)s[i] = num[len - i - 1] - '0';
        if (num[0]=='-')
        {
            len--;
        } 
        return *this;
    }
    bign operator =(int num)
    {
        memset(s, 0, sizeof(s));
        len = 1; 
        char ss[maxn];
        if (num >= 0) fh = 1;
        else fh = 0;
        sprintf(ss, "%d", num);
        *this = ss;
        return *this;
    }
    bign(int num) { *this = num; }
    bign(const char* num) { *this = num; }
    string str() const
    {
        string res = "";
        for (int i = 0; i < len; i++) res = (char)(s[i] + '0') + res;
        if (fh==0) res = (char)('-') + res;
        if (res == "")res = "0";
        return res;
    }
    bool operator < (const bign& b) const
    {
        if (len != b.len) return len < b.len;
        for (int i = len - 1; i >= 0; i--)
            if (s[i] != b.s[i]) return s[i] < b.s[i];
        return false;
    }
    bool operator >  (const bign& b)const { return b < *this; }
    bool operator <= (const bign& b)const { return !(b < *this); }
    bool operator >= (const bign& b)const { return !(*this < b); }
    bool operator != (const bign& b)const { return b < *this || *this < b; }
    bool operator == (const bign& b)const { return (b < *this) && !(*this < b); }
    bign operator + (const bign& b)const
    {
        if ((fh == 1) && (b.fh == 1))
        {
            bign c;
            c.len = 0;
            c.fh = 1;
            for (int i = 0, g = 0; g || i < max(len, b.len); i++)
            {
                int x = g;
                if (i < len) x += s[i];
                if (i < b.len) x += b.s[i];
                c.s[c.len++] = x % 10;
                g = x / 10;
            }
            c.clean();
            return c;
        }
        else if ((fh == 0) && (b.fh == 0))
        {
            bign c;
            c.len = 0;
            c.fh = 0;
            for (int i = 0, g = 0; g || i < max(len, b.len); i++)
            {
                int x = g;
                if (i < len) x += s[i];
                if (i < b.len) x += b.s[i];
                c.s[c.len++] = x % 10;
                g = x / 10;
            }
            c.clean();
            return c;
        }
        else if ((fh == 1) && (b.fh == 0) && (*this >= b))
        {
            bign c; c.len = 0; c.fh = 1;
            for (int i = 0, g = 0; i < len; i++)
            {
                int x = s[i] - g;
                if (i < b.len) x -= b.s[i];
                if (x >= 0) g = 0;
                else { g = 1; x += 10; }
                c.s[c.len++] = x;
            }
            c.clean();
            return c;
        }
        else if ((fh == 1) && (b.fh == 0) && (*this < b))
        {
            bign c; c.len = 0; c.fh = 0;
            for (int i = 0, g = 0; i < b.len; i++)
            {
                int x = b.s[i] - g;
                if (i < len) x -= s[i];
                if (x >= 0) g = 0;
                else { g = 1; x += 10; }
                c.s[c.len++] = x;
            }
            c.clean();
            return c;
        }
        else if ((fh == 0) && (b.fh == 1) && (*this <= b))
        {
            bign c; c.len = 0; c.fh = 1;
            for (int i = 0, g = 0; i < b.len; i++)
            {
                int x = b.s[i] - g;
                if (i < len) x -= s[i];
                if (x >= 0) g = 0;
                else { g = 1; x += 10; }
                c.s[c.len++] = x;
            }
            c.clean();
            return c;
        }
        else
        {
            bign c; c.len = 0; c.fh = 0;
            for (int i = 0, g = 0; i < len; i++)
            {
                int x = s[i] - g;
                if (i < b.len) x -= b.s[i];
                if (x >= 0) g = 0;
                else { g = 1; x += 10; }
                c.s[c.len++] = x;
            }
            c.clean();
            return c;
        }
    }
    bign operator - (const bign& b) 
    {
        bign bb=b;
        bb.fh = (1 - b.fh);
        return *this + b;
    }
    bign operator * (const bign& b) const
    {

        bign c; c.len =0;
        int la=len; int lb=b.len;
        for (int i=0;i<=la;i++)
            for (int ii=0;ii<=lb;ii++)
            {
                c.len=c.len+1;
                c.s[i+ii]+=(s[i]*b.s[ii]);
                while (c.s[i+ii]>=10)
                {
                    c.s[i+ii]-=10;
                    c.s[i+ii+1]++;
                }
            }
        c.clean();
        return c;
    }
    bign operator / (const bign& b) const
    {
        bign a=*this,c=0;
        while(a>=b)
        {
            a=a-b;
            c=c+1;  
        }
        c.clean();
        return c;
    }
};
istream& operator >>(istream &in, bign& x)
{
    string s;
    in >> s;
    if (s[0]=='-') x.fh=0;
    x = s.c_str();
    return in;
}
ostream& operator <<(ostream &out, bign& x)
{
    out << x.str();
    return out;
}

core
{
    memory bign a,b,c; 
    cin>>a>>b;
    c=a+b;
    cout<<c;
} 

by Zhoubohan2012 @ 2023-08-05 10:35:37


#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    int a,b;
    cin >> a >> b;
    cout << a+b << endl;
    return 0;
}

这么写他不香吗?

上一页 |