166 条题解
-
0
使用 C++ 风格的输入输出
#include <bits/stdc++.h>//头文件,可以暂时理解为告诉编译器你要拿标准库中的函数来用 using namespace std; //如果不想引入整个 std 命名空间,你需要使用 int main() { //std::cin、std::cout、std::endl int a, b; //定义整形变量 a 和 b,它们可存储的整数范围约为 ±21 亿, cin >> a >> b; //对于本题的数据范围绰绰有余;从标准输入中读入两个值并赋给 a, b cout << a + b; //输出结果。你也可以先使用另一个变量存储结果,但在这里没什么意义 return 0; //返回 0 以外的值会让操作系统或在线判题系统认为你的程序异常退出 } //最后的 return 0; 也可以不写,编译器会自动帮你加上正常退出
使用 C 语言风格的输入输出
#include <bits/stdc++.h> using namespace std; int main() { int a, b; //%d 是整形的占位符 scanf("%d %d", &a, &b); //输入非字符串时你需要在变量名前面加上取地址符 & printf("%d", a + b); //输出时不要加 &,否则你的输出会是一个地址而不是你想要的答案 return 0; //其余的部分请看上面的注释 }
-
-1
文言文
由【键盘】入之甲、乙二整形元素。 以操作符【+】计算甲、乙之和。 存入另一整形元素丙。书之。
伪代码(PQ)
set keyboard as stdin set screen as stdout input int1024 a b c=a(operator +)b output c as int1024
伪代码(XD20)
这个在XD22中也可运行function main begin. stdin a stdin b stdout a+b end.
伪代码(XD22)
select keyboard as stdin select screen as stdout gnu -O2 -Wall function main begin. stdin a stdin b stdout a+b end.
伪代码(Z)
select keyboard as input select screen as output select windows11 as system select Z22 as language select ZS22 as compiler begin. read a read b write a+b end. flush.
Pascal
var a, b: longint; begin readln(a,b); writeln(a+b); end.
C++
#include<bits/stdc++.h> using namespace std; int fu=1,f=1,a,b,c=0; int main(){ cin>>a>>b; if(a<0&&b>0)fu=2; if(a>0&&b<0)fu=3; if(a<0&&b<0)f=-1; if(a==0){cout<<b;return 0;} if(b==0){cout<<a;return 0;} a=abs(a); b=abs(b); if(a>b&&fu==3)f=1; if(b>a&&fu==3)f=-1; if(b>a&&fu==2)f=1; if(b<a&&fu==2)f=-1; if(fu==1)c=a+b; if(fu>1)c=max(a,b)-min(a,b); c*=f; cout<<c; return 0; }
-
-1
曾经的我:
#include<iostream> using namespace std; int main (){ int a,b; cin>>a>>b; cout<<a+b; return 0; }
现在的我:
#include<iostream> #include<string> using namespace std; int n1[501]; int m1[501]; int result[501]; string n,m; int main(){ cin>>n>>m; int ns,ms; ns=n.size(); ms=m.size(); for(int i=ns-1,j=1;i>=0;i--,j++){ n1[j]=n[i]-'0'; } for(int i=ms-1,j=1;i>=0;i--,j++){ m1[j]=m[i]-'0'; } int j=ns>ms?ns:ms; for(int i=1;i<=j;i++){ result[i]+=m1[i]+n1[i]; result[i+1]=result[i]/10; result[i]=result[i]%10; } if(result[j+1]){ j++; } for(int i=j;i>=1;i--){ cout<<result[i]; } return 0; }
感觉没啥变化
-
-1
注:此代码不支持C++23(O2)。
#include<bits/stdc++.h> #define short long long #define int long long #define float long double #define double long double #define char wchar_t #define ios ios::sync_with_stdio(0),cin.tie(0),cout.tie(0) using namespace std; signed main(){ ios; int a,b;//定义a,b cin>>a>>b;//输入a,b cout<<a+b;//输出a+b return 0;//结束程序 }
-
-1
信息
- ID
- 56
- 时间
- 1000ms
- 内存
- 1024MiB
- 难度
- 1
- 标签
- 递交数
- 9734
- 已通过
- 4392
- 上传者