---
# System prepended metadata

title: A+B Problem
tags: [C++]

---

# A+B Problem
## 題目敘述
![](https://i.imgur.com/XhuNCEz.png)
![](https://i.imgur.com/CjfssNP.png)
## 程式碼
```cpp=
#include <bits/stdc++.h>
using namespace std;

#define ll long long

string s;
vector<ll> v, cv;
ll ct=0;

void f(int l1, int l2, int l3){
	int as=l1, bs=l2, cs=l3;
	if((s[0]=='0' && l1!=1) || (s[l1]=='0' && l2!=1) || (s[l1+l2]=='0' && l3!=1));
	else{
		for(int i=0; i<l1; i++){
		ll n=s[i]-'0';
		v[0] += n*pow(10, as-1);
		as--;
		}
		for(int i=l1; i<l1+l2; i++){
			ll n=s[i]-'0';
			v[1] += n*pow(10, bs-1);
			bs--;
		}
		for(int i=l1+l2; i<l1+l2+l3; i++){
			ll n=s[i]-'0';
			v[2] += n*pow(10, cs-1);
			cs--;
		}
		if(v[0]+v[1]==v[2]){
			ct++;
			for(int i=0; i<3; i++)
				cv.push_back(v[i]);
		}
	}
}

int main(){
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	cin>>s;
	int len = s.size(), n3=3;;
	while(n3--) v.push_back(0);
	for(int i=1; i<=len-2; i++){
		int al, bl, cl;
		al = i;
		for(int j=1; j<=len-i-1; j++){
			bl = j;
			cl = len-i-j;
			f(al, bl, cl);
			for(int i=0; i<3; i++) v.insert(v.begin(), 0);
		}
	}
	cout<<ct<<'\n';
	for(int i=0; i<cv.size(); i=i+3)
		cout<<cv[i]<<" + "<<cv[i+1]<<" = "<<cv[i+2]<<'\n';
	
	return 0;
}
```
###### 闕以諾 2022/7/17
###### tags: `C++`