4 solutions

  • 7
    @ 2022-5-3 11:39:03

    像A+B这样的问题,必须采用高精才行

    #include <iostream>
    using namespace std;
    int w[2][550];
    string w1, w2;
    int main() {
    	cin >> w1;
    	cin >> w2;
    	int x1 = w1.length(), x2 = w2.length();
    	int t = max(x1, x2), len = 0;
    	for (int i = x1 - 1; i >= 0; i--) {
    		w[0][i] = w1[len++] - '0';
    	}
    	len = 0;
    	for (int j = x2 - 1; j >= 0; j--) {
    		w[1][j] = w2[len++] - '0';
    	}
    	for (int i = 0; i < t; i++) {
    		w[0][i] = w[0][i] + w[1][i];
    		w[0][i + 1] += w[0][i] / 10;
    		w[0][i] %= 10;
    
    	}
    	while (w[0][t] > 0) t++;
    	while (t != 0 && w[0][t] == 0) t--;
    	for (int i = t; i >= 0; i--) {
    		cout << w[0][i];
    	}
    	return 0;
    }
    

    补一发树状数组

    #include<iostream>
    #include<cstring>
    using namespace std;
    int lowbit(int a)
    {
    	return a&(-a);
    }
    int main()
    {
    	int n=2,m=1;
    	int ans[m+1];
    	int a[n+1],c[n+1],s[n+1];
    	int o=0;
    	memset(c,0,sizeof(c));
    	s[0]=0;
    	for(int i=1;i<=n;i++)
    	{
    		cin>>a[i];
    		s[i]=s[i-1]+a[i];
    		c[i]=s[i]-s[i-lowbit(i)];//树状数组创建前缀和优化
    	}
    	for(int i=1;i<=m;i++)
    	{
    		int q=2;
    		{
    			int x=1,y=2;//求a[1]+a[2]的和
    			int s1=0,s2=0,p=x-1;
    			while(p>0)
    			{
    				s1+=c[p];
    				p-=lowbit(p);//树状数组求和操作,用两个前缀和相减得到区间和
    			}
    			p=y;
    			while(p>0)
    			{
    				s2+=c[p];
    				p-=lowbit(p);
    			}    
    			o++;
    			ans[o]=s2-s1;//存储答案
    		}
    	}
    	for(int i=1;i<=o;i++)
    		cout<<ans[i]<<endl;//输出
    	return 0;
    }
  • 4
    @ 2021-10-12 0:30:12

    题目信息

    我们可以看到我们只需要输入两个值,然后输出他们的和即可,那么我们可以直接得到C++的代码:

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

    C语言的代码:

    main(){
    	int a,b;
    	scanf("%d %d",&a,&b);
        printf("%d\n",a+b);
    	return 0;
    }
    
    • 0
      @ 2023-10-18 9:38:21
      #include <stdio.h>
      int main()
      {
          unsigned int x;
          int y;
          scanf("%d %d",&x,&y);
          int sum;
          sum=x+y;
          printf("%d",sum);
          return 0;
      }
      
      • 0
        @ 2022-4-4 17:09:41

        简单题解(C++)

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

        Python

        while True:
            try:
                x = input().split()
                print(int(x[0])+int(x[1]))
            except:
                break
        
        
        • 1

        Information

        ID
        1
        Time
        1000ms
        Memory
        256MiB
        Difficulty
        6
        Tags
        # Submissions
        1587
        Accepted
        484
        Uploaded By