We've already tried comparing 3 numbers to see the largest among all, so let's try a more complicated mission where we locate where among the 5-digit integer is the largest one. There are only 4 possible cases for this mission:
Now, show me how far you've understood your lessons!
Input
A line containing a five-digit integer.
14632
Output
A line containing a string.
Middle
#include <iostream>
using namespace std;
int main()
{
int a;
cin>>a;
int fd=a/10000; // first digit
int md=(a/100)%10; // middle digit
int ld=a%10; // last digit
if ((fd>md)&&(fd>ld))
{
cout<<"Leftmost";
}
else if ((md>fd)&&(md>ld))
{
cout<<"Middle";
}
else if ((ld>fd)&&(ld>md))
{
cout<<"Rightmost";
}
else cout<<"Unknown";
}
Comments
Leave a comment