int main() { long long int total; long long int init; scanf("%lld %lld", &total, &init); getchar(); long long int max = init; long long int min = init; int i; for (i = 0; i < total; i++) { char op1 = '0'; char op2 = '0'; long long int num1 = 0; long long int num2 = 0; scanf("%c %lld %c %lld", &op1, &num1, &op2, &num2); getchar(); long long int maxr = max; long long int minr = min; if (op1 == '+') { long long int sum = max + num1; maxr = sum; minr = sum; long long int res = min + num1; if (res > maxr) { max = res; } if (res < minr) { minr = res; } } else { long long int sum = max * num1; maxr = sum; minr = sum; long long int res = min * num1; if (res > maxr) { maxr = res; } if (res < minr) { minr = res; } } if (op2 == '+') { long long int sum = max + num2; if (sum > maxr) { maxr = sum; } if (sum < minr) { minr = sum; } long long int res = min + num2; if (res > maxr) { maxr = res; } if (res < minr) { minr = res; } } else { long long int sum = max * num2; if (sum > maxr) { maxr = sum; } if (sum < minr) { minr = sum; } long long int res = min * num2; if (res > maxr) { maxr = res; } if (res < minr) { minr = res; } } min = minr; max = maxr; } printf("%lld\n", max); return 0; } Sample Input #1 3 123 + 100 x 2 + -100 x -2 + 0 + 0 Sample Output #1 146 Can u give general explaination for this code, so i can learn it.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
int main()
{
long long int total;
long long int init;
scanf("%lld %lld", &total, &init);
getchar();
long long int max = init;
long long int min = init;
int i;
for (i = 0; i < total; i++)
{
char op1 = '0';
char op2 = '0';
long long int num1 = 0;
long long int num2 = 0;
scanf("%c %lld %c %lld", &op1, &num1, &op2, &num2);
getchar();
long long int maxr = max;
long long int minr = min;
if (op1 == '+')
{
long long int sum = max + num1;
maxr = sum;
minr = sum;
long long int res = min + num1;
if (res > maxr)
{
max = res;
}
if (res < minr)
{
minr = res;
}
}
else
{
long long int sum = max * num1;
maxr = sum;
minr = sum;
long long int res = min * num1;
if (res > maxr)
{
maxr = res;
}
if (res < minr)
{
minr = res;
}
}
if (op2 == '+')
{
long long int sum = max + num2;
if (sum > maxr)
{
maxr = sum;
}
if (sum < minr)
{
minr = sum;
}
long long int res = min + num2;
if (res > maxr)
{
maxr = res;
}
if (res < minr)
{
minr = res;
}
}
else
{
long long int sum = max * num2;
if (sum > maxr)
{
maxr = sum;
}
if (sum < minr)
{
minr = sum;
}
long long int res = min * num2;
if (res > maxr)
{
maxr = res;
}
if (res < minr)
{
minr = res;
}
}
min = minr;
max = maxr;
}
printf("%lld\n", max);
return 0;
}
Sample Input #1
3 123
+ 100 x 2
+ -100 x -2
+ 0 + 0
Sample Output #1
146
Can u give general explaination for this code, so i can learn it.
Step by step
Solved in 4 steps