Competitve Programming : Dealing With If.
Minimum dimension of the picture can be L x L, where L is the length of the side of square.
Minimum dimension of the picture can be L x L, where L is the length of the side of square.
Now Roy has N photos of various dimensions.
Dimension of a photo is denoted as W x H
where W - width of the photo and H - Height of the photo
Dimension of a photo is denoted as W x H
where W - width of the photo and H - Height of the photo
When any photo is uploaded following events may occur:
[1] If any of the width or height is less than L, user is prompted to upload another one. Print "UPLOAD ANOTHER" in this case.
[2] If width and height, both are large enough and
(a) if the photo is already square then it is accepted. Print "ACCEPTED" in this case.
(b) else user is prompted to crop it. Print "CROP IT" in this case.
[2] If width and height, both are large enough and
(a) if the photo is already square then it is accepted. Print "ACCEPTED" in this case.
(b) else user is prompted to crop it. Print "CROP IT" in this case.
(quotes are only for clarification)
Given L, N, W and H as input, print appropriate text as output.
Input:
First line contains L.
Second line contains N, number of photos.
Following N lines each contains two space separated integers W and H.
First line contains L.
Second line contains N, number of photos.
Following N lines each contains two space separated integers W and H.
Output:
Print appropriate text for each photo in a new line.
Print appropriate text for each photo in a new line.
Constraints:
1 <= L,W,H <= 10000
1 <= N <= 1000
1 <= L,W,H <= 10000
1 <= N <= 1000
Source Code :
#include<conio.h>
#inlcude<stdio.h>
int main(){
int L,W[1000],H[1000],N,i;
scanf("%d",&L);
scanf("%d",&N);
for(i=0;i<N;i++)
{
scanf("%d%d",&W[i],&H[i]);
}
for(i=0;i<N;i++)
{
if(W[i]>=L&&H[i]>=L)
{
if(W[i]*H[i]<=(L*L))
{
printf("\nACCEPTED ");
}
else if((W[i]==H[i]))
{
printf("\nACCEPTED ");
}
else if((W[i]*H[i]>L*L))
{
printf("\nCROP IT");
}
}
else if(W[i]<L||H[i]<L)
{
printf("\nUPLOAD ANOTHER ");
}
}
PS : Here TO avoid Dangling if else problem We have used Nested if.