A + B

A + B

成功
给出2个整数A和B,计算两个数的和。
收起
输入
2个整数A B,中间用空格分割。(0 <= A, B <= 10^9)
输出
输出A + B的计算结果。
输入样例
1 2
输出样例
3

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

新版的编程挑战中C及C++的编译器用的是MinGW64(4.9.2),VC的编译器为CL,Microsoft ® C/C++ 优化编译器 18.00.30723 版

选择C语言的提交,编译参数为:
gcc.exe -m64 -pipe -static -lm -s -std=c99 -O2

选择C 11语言的提交,编译参数为:
gcc.exe -m64 -pipe -static -lm -s -std=c11 -O2

选择C++语言的提交,编译参数为:
g++.exe -m64 -pipe -static -lm -s -x c++ -O2

选择C++ 11语言的提交,编译参数为:
g++.exe -m64 -pipe -static -lm -s -x c++ -std=c++11 -O2

选择Visual C++ 语言的提交,编译参数为:
cl.exe /O2 /GA /W0 /EHsc /nologo

选择Objective-C语言的提交,编译参数为:

-I …\Library\Headers -L …\Library\Libraries -fconstant-string-class=NSConstantString -lobjc -lgnustep-base

C关于A + B的示例:
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>

int solveMeFirst(int a, int b) {
return a+b;
}
int main() {
int num1,num2;
scanf("%d %d",&num1,&num2);
int sum;
sum = solveMeFirst(num1,num2);
printf("%d",sum);
return 0;
}

C++关于A + B的示例:
#include
#include
#include
#include
#include
using namespace std;

int solveMeFirst(int a, int b) {
return a+b;
}
int main() {
int num1, num2;
int sum;
cin>>num1>>num2;
sum = solveMeFirst(num1,num2);
cout<<sum;
return 0;
}

OC关于A + B的示例:
#import <Foundation/Foundation.h>
int solveMeFirst(int a, int b) {
return a+b;
}

int main (int argc, const char * argv[]) {
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int a,b,res;
scanf("%d %d", &a, &b);
res = solveMeFirst(a,b);
printf("%d", res);
[pool drain];
return 0;
}

各种版本的C及C++,运行时限为基础时限 * 1。

对于一些因为递归太深,导致爆栈的程序,可以使用扩栈语句,但仅限VC编译。

#pragma comment(linker, “/STACK:10240000,10240000”)

注意后面的栈大小,太大会导致内存使用超出!

新版OJ已经解决了I64d等输入输出问题。

关于优化输入输出的速度:

C及C++尽量使用printf和scanf,可以加快读入和输出数据的速度。

建议C++用户include使用:stdio.h,不用:cstdio,详情请看这个链接:
http://stackoverflow.com/questions/17236352/mingw-w64-slow-sprintf-in-cstdio

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值