How much Scholarship Codechef Solution

How much Scholarship Codechef Solution

Problem

How much Scholarship Codechef Solution: The ZCO Scholarship Contest has just finished, and you finish with a rank of RR. You know that Rank 11 to Rank 5050 will get 100%100% scholarship on the ZCO exam fee and Rank 5151 to Rank 100100 will get 50%50% percentage scholarship on the ZCO exam fee. The rest do not get any scholarship.
What percentage of scholarship will you get ?

Input

  • Input consist of single line of input containing one integer RR.

Output

  • Output a single line containing one integer — the percentage of scholarship you will get.

Constraints

  • 1≤R≤109

Sample Input 

49

Sample Output 

100

How much Scholarship  – CodeChef Solution in CPP

#include<iostream>
using namespace std;
int main()
{
    unsigned long long rank;
    cin >> rank;
    if (rank > 100)
    {
        cout << 0 << endl;
        return 0;
    }
    else if (rank >= 1 && rank <= 50)
        cout << 100 << endl;
    else if (rank >= 51 && rank <= 100)
        cout << 50 << endl;
    return 0;
}

  How much Scholarship  – CodeChef Solution in JAVA

public static void main(String[] args)
{
	long rank;
	rank = Long.parseLong(ConsoleInput.readToWhiteSpace(true));
	if (rank > 100)
	{
		System.out.print(0);
		System.out.print("\n");
	}
	else if (rank >= 1 && rank <= 50)
	{
		System.out.print(100);
		System.out.print("\n");
	}
	else if (rank >= 51 && rank <= 100)
	{
		System.out.print(50);
		System.out.print("\n");
	}
}
package tangible;
public final class ConsoleInput
{
	private static boolean goodLastRead = false;
	public static boolean lastReadWasGood()
	{
		return goodLastRead;
	}
	public static String readToWhiteSpace(boolean skipLeadingWhiteSpace)
	{
		String input = "";
		char nextChar;
		while (Character.isWhitespace(nextChar = (char)System.in.read()))
		{
			//accumulate leading white space if skipLeadingWhiteSpace is false:
			if (!skipLeadingWhiteSpace)
			{
				input += nextChar;
			}
		}
		//the first non white space character:
		input += nextChar;
		//accumulate characters until white space is reached:
		while (!Character.isWhitespace(nextChar = (char)System.in.read()))
		{
			input += nextChar;
		}
		goodLastRead = input.length() > 0;
		return input;
	}
	public static String scanfRead()
	{
		return scanfRead(null, -1);
	}
	public static String scanfRead(String unwantedSequence)
	{
		return scanfRead(unwantedSequence, -1);
	}
	public static String scanfRead(String unwantedSequence, int maxFieldLength)
	{
		String input = "";
		char nextChar;
		if (unwantedSequence != null)
		{
			nextChar = '\0';
			for (int charIndex = 0; charIndex < unwantedSequence.length(); charIndex++)
			{
				if (Character.isWhitespace(unwantedSequence.charAt(charIndex)))
				{
					//ignore all subsequent white space:
					while (Character.isWhitespace(nextChar = (char)System.in.read()))
					{
					}
				}
				else
				{
					//ensure each character matches the expected character in the sequence:
					nextChar = (char)System.in.read();
					if (nextChar != unwantedSequence.charAt(charIndex))
						return null;
				}
			}
			input = (new Character(nextChar)).toString();
			if (maxFieldLength == 1)
				return input;
		}
		while (!Character.isWhitespace(nextChar = (char)System.in.read()))
		{
			input += nextChar;
			if (maxFieldLength == input.length())
				return input;
		}
		return input;
	}
}

Disclaimer: The above Problem (How much Scholarship) is generated by CodeChef but the solution is provided by  Chase2learn. This tutorial is only for Educational and Learning purpose.

Leave a Comment