10 条题解

  • 0
    @ 2025-12-1 19:39:54
    #include<iostream>
    #include<string>
    using namespace std;
    string add(string a,string b){
    	string result = "";
    	int i=a.length()-1;
    	int j = b.length()-1;
    	int carry=0;
    	while(i>=0||j>=0||carry>0){
    		int sum=carry;
    		if(i>=0){
    			sum+=a[i]-'0';
    			i--;
    		}
    		if(j>=0){
    			sum+=b[j]-'0';
    			j--;
    		}
    		carry=sum/10;
    		result=char(sum%10+'0')+result;
    	}
    	return result;	
    }
    int main()
    {
    	int t;
    	cin>>t;
    	for(int c=1;c<=t;c++){
    		string a,b;
    		cin>>a>>b;
    		string sum=add(a,b);
    		cout<<"Case"<<" "<<c<<":"<<endl;
    		cout<<a<<" "<<"+"<<" "<<b<<" "<<"="<<" "<<sum<<endl;
    	}
    	return 0;
     } 
    
    • @ 2025-12-1 19:40:47

      记得打空格😕

信息

ID
165
时间
3000ms
内存
128MiB
难度
8
标签
(无)
递交数
1611
已通过
205
上传者