Codechef : Problem name " ATM Machine " solution in C#
===========================Solution========================
using System;
public class Test
{
public static void Main()
{
int t=Convert.ToInt32(Console.ReadLine());
for(int i=0;i<t;i++){
string[] array=Console.ReadLine().Split(' ');
int N=Convert.ToInt32(array[0]);
int K=Convert.ToInt32(array[1]);
string[] arrayUsers=Console.ReadLine().Split(' ');
for(int j=0; j<arrayUsers.Length;j++)
{
if (Convert.ToInt32(arrayUsers[j]) <= K)
{
Console.Write(1);
K = K - Convert.ToInt32(arrayUsers[j]);
}
else
{
Console.Write(0);
}
}
Console.Write("\n");
}
}
}
==========================Explanation========================
We have input from each customer
First in loop we check if the amount put by the user is less than equal to total amount present in ATM
If the amount entered by the user is less than the amount present in the ATM, then we will withdraw money for that person and then we decrement the amount which has been withdrawn by the user and ask for the next user input
If successful to withdraw ten we print 1, else we print 0
First in loop we check if the amount put by the user is less than equal to total amount present in ATM
If the amount entered by the user is less than the amount present in the ATM, then we will withdraw money for that person and then we decrement the amount which has been withdrawn by the user and ask for the next user input
If successful to withdraw ten we print 1, else we print 0
Comments
Post a Comment