Codeforces The number of positions

**********************************  Solution 1 *****************************
#include<bits/stdc++.h>
using namespace std;

#define tofast ios_base::sync_with_stdio(false)

int main()
{
    tofast;
    int n, a , b;
    while(cin >> n >> a >> b)
    {
        int ans=0;

        for(int i=a+1; i<=n ; i++)
        {
            if(n - i <= b) ans++;
        }

        cout << ans << "\n";
    }

    return 0;
}

******************************Solution 2*******************************************
#include<bits/stdc++.h>
using namespace std;

#define tofast ios_base::sync_with_stdio(false)

int main()
{
    tofast;

    int n, a, b;

    while(cin >> n >> a >> b)
    {
        cout << min(n-a, b+1) << "\n" ; // ultimate result to see the pattern of previous solution
    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number