C++ Should curly braces be on their own line or not?

if (you.hasAnswer()) {
you.postAnswer();
} else {
you.doSomething();
}
if (you.hasAnswer())
{
you.postAnswer();
}
else
{
you.doSomething();
}
if (you.hasAnswer())
you.postAnswer();
else
you.doSomething();
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX=50050;
int t,N;
int tr[MAX<<4];
void re(int x)
{
tr[x]=tr[x*2]+tr[x*2+1];
}
void build(int st,int ed,int node)
{
if(st==ed)
{
scanf("%d",&tr[node]);
return;
}
int mid=(st+ed)>>1;
build(st,mid,node<<1);
build(mid+1,ed,(node<<1)+1);
re(node);
}
void update(int st,int ed,int node,int id,int val)
{
if(st==ed)
{
tr[node]+=val;
return;
}
int mid=(st+ed)>>1;
if(id<=mid)
{
update(st,mid,node<<1,id,val);
}
else
{
update(mid+1,ed,node<<1|1,id,val);
}
re(node);
}
int query(int st,int ed,int node,int l,int r)
{
if(r<st||l>ed) return 0;
else if(st>=l&&ed<=r) return tr[node];
int mid=(st+ed)>>1;
int l_sum=query(st,mid,node<<1,l,r);
int r_sum=query(mid+1,ed,node<<1|1,l,r);
return l_sum+r_sum;
}
int main()
{
scanf("%d",&t);
for(int k=1;k<=t;k++)
{
scanf("%d",&N);
printf("Case %d:\n",k);
build(1,N,1);
char op[10];
while(scanf("%s",op))
{
if(op[0]=='E')
{
break;
}
int i,j;
scanf("%d %d",&i,&j);
if(op[0]=='A')
{
update(1,N,1,i,j);
}
if(op[0]=='S')
{
update(1,N,1,i,-j);
}
if(op[0]=='Q')
{
cout<<query(1,N,1,i,j)<<endl;
}
}
}
return 0;
}

--

--

--

Data Scientist/MLE/SWE @takemobi

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Will I get a job after my coding bootcamp?

Move with the times — decentralize Enterprise Architecture

Promoted Tuna DApp From Local to Docker container along with Mongo container

Using three multisets

Laravel Request Lifecycle

How to start WordPress plugin development with Docker, Part 1: Docker and Admin Panel

Advanced web scraping in Python

After reading this comic, you will definitely understand HTTPS

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jimmy Shen

Jimmy Shen

Data Scientist/MLE/SWE @takemobi

More from Medium

A Case for Spliff

Understanding the ES6 Spread Operator

Safe Cracking