# Chef And Offers - Editorial

[Practice] CENV002 Problem - CodeChef
[Codennovate] CodeChef: Practical coding for everyone

Author: [Akshat Goyal] beast787 | CodeChef User Profile for Akshat Goyal | CodeChef
Editorialist: [Akshat Goyal] beast787 | CodeChef User Profile for Akshat Goyal | CodeChef

DIFFICULTY: Easy
# PREREQUISITES: Math

Problem with explanation:
The input is N- 4 digit customerID and we have to take out the discount on the formula

(First_digit+last_digit)*Max_digit and if discount is >100 than output 100 else output actual discount.

Calculate last digit: n/1000;

Calculate first digit:n%10;

Calculate max digit by taking out every digit through following algorithm

M=0

While(n!=0)

d=n%10

n=n/10

m=max(d,m);

Finally Outside the loop calculate ans=(First_digit+last_digit)*Max_digit and check if ans>100 then output 100 else output ans.

#Solutions:

Editorialist’s &Tester’s Solution

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define mod 1e9+7
#define For(i,n) for(int i=0;i<n;i++)
#define map map<int,int>
#define all(x) x.begin(),x.end()
void solve() {
int n;
cin>>n;
int a[n];
For(i,n)
{
cin>>a[i];
}
For(i,n)
{
int num,maxi=0,sum=0,d;
num=a[i];
sum+=num%10;
sum+=a[i]/1000;
while(num!=0)
{
d=num%10;
num=num/10;
if(d>maxi)
maxi=d;
}
if(summaxi>=100)
cout<<“100”<<endl;
else
cout<<sum
maxi<<endl;

}
}

int main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
solve();
}