April Fools Contest 2017, problem: (G) BF Calculator Solution in C/C++

#include<cstdio>
int main()
{
int ans=0,a=0; char c;
scanf(“%d”,&ans);
while (scanf(“%c%d”,&c,&a) != EOF)
{
if (c==’+’) ans+=a;
if (c==’-‘) ans-=a;
}
a=0;
if (ans==0)
{
printf(“++++++++++++++++++++++++++++++++++++++++++++++++.”);
return 0;
}
while (ans)
{
int x=ans%10;
for (int i=1;i<=x;i++) printf(“+”);
printf(“++++++++++++++++++++++++++++++++++++++++++++++++”);
printf(“>”);
ans/=10;
a++;
}
while (a–) printf(“<.”);
printf(“\n”);
return 0;
}

(Visited 50 times, 1 visits today)

About the Author:

Leave A Comment