Question 10

5 comments on “Question 10”


  • culbgaming12

    #include
    using namespace std;

    int main()
    {

    int n;

    cin >> n;

    int b[n];

    for (int i = 0; i > b[i];
    }

    int min_no_loaves = 0;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
    sum += b[i];

    if (sum % 2 != 0)
    {
    min_no_loaves += 2;
    }
    }

    if (sum % 2 == 0)
    {
    cout << min_no_loaves << endl;
    }

    else
    {
    cout << "NO" << endl;
    }

    return 0;
    }


  • Shivam

    #include
    using namespace std;
    int main()
    {
    int size,i;
    cin>>size;
    vector v;
    for(i=0;i>no;
    v.push_back(no);
    }
    // sort(v.begin(),v.end());
    int count=0;
    for(i=0;i<size;i++)
    {
    if(v[i]%2!=0)
    {
    v[i]=v[i]+1;
    v[i+1]=v[i+1]+1;
    count+=2;
    }
    }
    if(v[size]%2==0)
    {
    cout<<endl<<count;
    }
    else
    {
    cout<<"No";
    }
    }


  • Pratik

    def fairRations(B):
    breads = 0
    n = len(B)
    for i in range(n-1):
    if B[i]%2 == 1:
    breads +=2
    B[i+1] += 1

    if B[n-1]%2 ==1:
    return “NO”
    else:
    return breads

    n = int(input())
    B = list(map(int, input().rstrip().split()))
    result = fairRations(B)
    print(result)


  • Gangadhar

    package com.code4you.Loaves_Distribution;

    import java.util.Scanner;

    public class Solution {

    public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    System.out.println(“Enter the number of subjects in the bread line:”);
    int n = sc.nextInt();
    System.out.println(“Enter ” + n + ” breadlines”);
    int[] loaves = new int[n];
    for (int i = 0; i < loaves.length; i++) {
    loaves[i] = sc.nextInt();
    }
    int count = 0;
    for (int i = 0; i < loaves.length – 1; i++) {
    if (isEven(loaves[i])) {
    continue;
    } else {
    loaves[i]++;
    loaves[i + 1]++;
    count += 2;
    }
    }
    if (isEven(loaves[loaves.length – 1])) {
    System.out.println("the minimum number of loaves: " + count);
    } else {
    System.out.println("NOT Possible");
    }
    }

    private static boolean isEven(int num) {
    if (num % 2 == 0) {
    return true;
    }
    return false;
    }
    }


  • 217-Sritej

    #include

    using namespace std;

    int main()
    { int n;
    cout<>n;
    int b[n];
    int m=0,i;
    //since minimum dena hai and even rakhna hai mai just 1 bread hi dunga aage ya peeche bassaathme
    for(i=0;i>b[i];
    }

    //0 bread hai to bhi aek dena hoga aur
    for(i=0;i<n;i++)
    {
    if(b[i]%2!=0||b[i]==0)
    {
    if(b[i]==0)
    {
    b[i]=b[i]+2;
    m=m+1; //neeche 2 add hohi rahe hai
    }
    if(b[i]!=0)
    {
    b[i]=b[i]+1;//iska neeche included hai
    }
    if(b[i-1]%2!=0&&(i!=0)) //first term
    {
    b[i-1]=b[i-1]+1;
    }
    else if(i!=(n-1)) //last term //yahi add karna hoga cause peeche we are not gonna traverse back
    {
    b[i+1]=b[i+1]+1;
    }

    if(i==n-1)
    {
    m=m+1;
    }
    else{
    m=m+2;
    }
    }
    //so basically everytime loaf add hoga to aage hi hoga cause peeche ka aleady sorted hai
    }
    cout<<m;
    return 0;
    }