ntxzgui @ 2024-12-14 15:09:55
using namespace std; int main(){
#include <bits/stdc++.h>
using namespace std;
int main(){
int a,b;
cin>>a>>b;
if(a>=0&&b>=0){
cout<<a+b<<endl;
}else if(a<0&&b>=0||a>=0&&b<0){
cout<<b+a<<endl;
}else if(a<0&&b<0){
cout<<0-(0-a+0-b)<<endl;
}else if(a=b=0){
} cout<<0<<endl;
return 0;
}
by niuniudundun @ 2024-12-14 15:13:11
@ntxzgui
a=b=0
赋值 =
和比较 ==
。
by niuniudundun @ 2024-12-14 15:14:58
@ntxzgui
直接输出
by Felixy_2012 @ 2024-12-14 15:16:31
@ntxzgui
太闲了吧
by yangyumo @ 2024-12-16 21:03:58
a+b就行了,不用你这样堆代码量
by yjj13621355890 @ 2025-01-03 19:14:50
@yangyumo是是是
by yjj13621355890 @ 2025-01-03 19:20:19
直接给你代码好吧
#include<iostream>//头文件好吧
using namespace std;//名称空间好吧
int main()//主函数好吧
{
int a,b;//定义好吧
cin>>a>>b;//输入好吧
cout<<a+b;//输出好吧
return 0;//返回好吧
}
/*好吧好吧大哥*/
by liuzhuoran141516 @ 2025-01-11 22:56:25
@yjj13621355890 我不允许你不会高精度
#include <bits/stdc++.h>
using namespace std;
bool cmp(string a, string b) {//比较大小
if (a.length() != b.length()) return a.length() > b.length();
return a > b;
}
string sub(string a, string b) {//高精减(没有负数)
string res;
int c = 0;
int i = a.length() - 1;
int j = b.length() - 1;
while (i >= 0 || j >= 0) {
int d1 = (i >= 0) ? (a[i--] - '0') : 0;
int d2 = (j >= 0) ? (b[j--] - '0') : 0;
int diff = d1 - d2 - c;
if (diff < 0) {
diff += 10;
c = 1;
} else {
c = 0;
}
res.push_back(diff + '0');
}
while (res.length() > 1 && res.back() == '0') res.pop_back();
reverse(res.begin(), res.end());
return res;
}
string add(string a, string b) {//高精加
bool na = (a[0] == '-');
bool nb = (b[0] == '-');
string x = na ? a.substr(1) : a;
string y = nb ? b.substr(1) : b;
if (!na && !nb) {
string res;
int c = 0;
int i = x.length() - 1;
int j = y.length() - 1;
while (i >= 0 || j >= 0 || c) {
int s = c;
if (i >= 0) s += x[i--] - '0';
if (j >= 0) s += y[j--] - '0';
c = s / 10;
res.push_back((s % 10) + '0');
}
reverse(res.begin(), res.end());
return res;
} else if (na && nb) {
return "-" + add(x, y);
} else {
bool xg = cmp(x, y);
string res;
if (xg) {
res = sub(x, y);
if (na) {
res = "-" + res;
}
} else {
res = sub(y, x);
if (nb) {
res = "-" + res;
}
}
return res;
}
}
string a, b;
int main() {
cin >> a >> b;
cout << add(a, b);
return 0;
}//牢弟,你还年轻