← Discussion

Less Code Less Code

Ln (x) dx · 2015-03-23 21:51:27

OOOOhhhhhhhhh! How can i reduce my code length in c++?

MaHaN Tp · 2015-03-23 22:37:53

Show your code

Ln (x) dx · 2015-03-26 01:58:39

It's 82 characters length. I want to get 74.

#include<iostream>
int main()
{
    for(int a,b;std::cin>>a>>b;std::cout<<a+b<<std::endl);  
}

MaHaN Tp · 2015-03-26 11:29:23

I think it can't be less than this :

#include<iostream>
int main(){int a,b;while(std::cin>>a>>b)std::cout<<a+b<<std::endl;}

Ln (x) dx · 2015-03-26 16:15:09

no it's 1 character longer. it's 83 chars.

AMiR · 2015-03-28 05:20:08

K Λ K T ♥ ♥ Ӡ said:

It's 82 characters length. I want to get 74.

#include<iostream>
int main()
{
    for(int a,b;std::cin>>a>>b;std::cout<<a+b<<std::endl);  
}

You don't have to specifiy your main function returns int. Just drop the int in int main(). This reduces the length to 79.

You can also replace std::endl with "\n". This will get you to 74 characters.

Moh$en · 2017-05-07 10:21:10

while 1:
    print sum(map(int,raw_input().split()))
pages:
  • 1