loading...

Daily Coding Challenge #78

wingkwong profile image Wing-Kam ・3 min read

Daily Coding Challenge (92 Part Series)

1) Daily Coding Challenge #1 2) Daily Coding Challenge #2 3 ... 90 3) Daily Coding Challenge #3 4) Daily Coding Challenge #4 5) Daily Coding Challenge #5 6) Daily Coding Challenge #6 7) Daily Coding Challenge #7 8) Daily Coding Challenge #8 9) Daily Coding Challenge #9 10) Daily Coding Challenge #10 11) Daily Coding Challenge #11 12) Daily Coding Challenge #12 13) Daily Coding Challenge #13 14) Daily Coding Challenge #14 15) Daily Coding Challenge #15 16) Daily Coding Challenge #16 17) Daily Coding Challenge #17 18) Daily Coding Challenge #18 19) Daily Coding Challenge #19 20) Daily Coding Challenge #20 21) Daily Coding Challenge #21 22) Daily Coding Challenge #22 23) Daily Coding Challenge #23 24) Daily Coding Challenge #24 25) Daily Coding Challenge #25 26) Daily Coding Challenge #26 27) Daily Coding Challenge #27 28) Daily Coding Challenge #28 29) Daily Coding Challenge #29 30) Daily Coding Challenge #30 31) Daily Coding Challenge #31 32) Daily Coding Challenge #32 33) Daily Coding Challenge #33 34) Daily Coding Challenge #34 35) Daily Coding Challenge #35 36) Daily Coding Challenge #36 37) Daily Coding Challenge #37 38) Daily Coding Challenge #38 39) Daily Coding Challenge #39 40) Daily Coding Challenge #40 41) Daily Coding Challenge #41 42) Daily Coding Challenge #42 43) Daily Coding Challenge #43 44) Daily Coding Challenge #44 45) Daily Coding Challenge #45 46) Daily Coding Challenge #46 47) Daily Coding Challenge #47 48) Daily Coding Challenge #48 49) Daily Coding Challenge #49 50) Daily Coding Challenge #50 51) Daily Coding Challenge #51 52) Daily Coding Challenge #52 53) Daily Coding Challenge #53 54) Daily Coding Challenge #54 55) Daily Coding Challenge #55 56) Daily Coding Challenge #56 57) Daily Coding Challenge #57 58) Daily Coding Challenge #58 59) Daily Coding Challenge #59 60) Daily Coding Challenge #60 61) Daily Coding Challenge #61 62) Daily Coding Challenge #62 63) Daily Coding Challenge #63 64) Daily Coding Challenge #64 65) Daily Coding Challenge #65 66) Daily Coding Challenge #66 67) Daily Coding Challenge #67 68) Daily Coding Challenge #68 69) Daily Coding Challenge #69 70) Daily Coding Challenge #70 71) Daily Coding Challenge #71 72) Daily Coding Challenge #72 73) Daily Coding Challenge #73 74) Daily Coding Challenge #74 75) Daily Coding Challenge #75 76) Daily Coding Challenge #76 77) Daily Coding Challenge #77 78) Daily Coding Challenge #78 79) Daily Coding Challenge #79 80) Daily Coding Challenge #80 81) Daily Coding Challenge #81 82) Daily Coding Challenge #82 83) Daily Coding Challenge #83 84) Daily Coding Challenge #84 85) Daily Coding Challenge #85 86) Daily Coding Challenge #86 87) Daily Coding Challenge #87 88) Daily Coding Challenge #88 89) Daily Coding Challenge #89 90) Daily Coding Challenge #90 91) Daily Coding Challenge #91 92) Daily Coding Challenge #92

About

This is a series of Daily Coding Challenge. Each day I show a few solutions written in C++. The questions are from coding practice/contest sites such as HackerRank, LeetCode, Codeforces, Atcoder and etc.


/*
M-SOLUTIONS Programming Contest 2020 - A - Kyu in AtCoder
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_a
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    int t; 
    cin >> t;
    // straightforward .. follow the Problem Statement
    if(t>=400&&t<=599) cout << 8;
    else if(t>=600&&t<=799) cout << 7;
    else if(t>=800&&t<=999) cout << 6;
    else if(t>=1000&&t<=1199) cout << 5;
    else if(t>=1200&&t<=1399) cout << 4;
    else if(t>=1400&&t<=1599) cout << 3;
    else if(t>=1600&&t<=1799) cout << 2;
    else if(t>=1800&&t<=1999) cout << 1;
    return 0;
} 

/*
M-SOLUTIONS Programming Contest 2020 - B - Magic 2
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_b
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    int a,b,c,k;
    cin >> a >> b >> c >> k;
    int ok=0;
    while(k--){
        // The integer on the green card is strictly greater than the integer on the red card.
        // The integer on the blue card is strictly greater than the integer on the green card.
        // i.e. c > b > a
        // if b is less than or equal to a, multiply b by 2
        if(b<=a) b*=2;
        // if c<=a, then multiply c by 2 
        // we don't need to multiply a by 2 since it should be the smallest one
        else c*=2;
    }
    // check if it is successful
    if(b>a&&c>b) cout << "Yes\n";
    else cout <<"No\n";
    return 0;
} 

/*
M-SOLUTIONS Programming Contest 2020 - C - Marks
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
*/

#include <bits/stdc++.h>
using namespace std; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    int n,k;
    cin >> n >> k;
    vector<long long> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    for(int i=0;i<n-k;i++){
        // we don't need to calculate the grade 
        // grade for the (K+i)-th term and that for the (K+i-1)-th term have (k-1) common elements 
        // therefore, just compare a[i] and a[i+k]
        if(a[i]<a[i+k]) cout <<"Yes\n";
        else cout <<"No\n";
    }

    return 0;
} 

// WA
//int main()  
//{ 
//    FAST_INP;
//    int n,k;
//    cin >> n >> k;
//    vector<long long> a(n), g(n-k+1);
//    for(int i=0;i<n;i++) cin >> a[i];
//    for(int i=0;i<n-k+1;i++){
//      int j=k+i-1;
//      long long sum=1;
//      for(int x=0;x<k;x++){
////            printf("%d * %d \n", sum , a[j-x]);
//          sum*=a[j-x];
//      }
////        printf("%d = %d\n", g[i],sum);
//      g[i] = sum;
//  }
//  for(int i=1;i<n-k+1;i++){
////        printf("%d %d \n", g[i],g[i-1]);
//      if(g[i]>g[i-1]) cout << "Yes\n";
//      else cout << "No\n";
//  }
//    return 0;
//} 

/*
M-SOLUTIONS Programming Contest 2020 - D - Road to Millionaire
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_d
*/

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

typedef long long ll; 
#define FAST_INP  ios_base::sync_with_stdio(false);cin.tie(NULL)

int main()  
{ 
    FAST_INP;
    int n;
    cin >> n;
    vector<ll> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    ll ans = 1000;
    for(int i=0;i<n-1;i++){
        // greedy - buy low sell high
        ll stock=0;
        if(a[i]<a[i+1]) stock = ans/a[i];
        ans+=(a[i+1]-a[i])*stock;
    }
    cout << ans << endl;
    return 0;
} 

The source code is available in corresponding repo below. Star and watch for timely updates!

GitHub logo wingkwong / leetcode

🏆 A Collection of my LeetCode Solutions with Explanations 🏆

GitHub logo wingkwong / hackerrank

🏆 A Collection of my HackerRank Solutions with Explanations 🏆

GitHub logo wingkwong / codeforces

🏆 A Collection of my Codeforces Solutions with Explanations 🏆

GitHub logo wingkwong / atcoder

🏆 A Collection of my AtCoder Solutions with Explanations 🏆

Daily Coding Challenge (92 Part Series)

1) Daily Coding Challenge #1 2) Daily Coding Challenge #2 3 ... 90 3) Daily Coding Challenge #3 4) Daily Coding Challenge #4 5) Daily Coding Challenge #5 6) Daily Coding Challenge #6 7) Daily Coding Challenge #7 8) Daily Coding Challenge #8 9) Daily Coding Challenge #9 10) Daily Coding Challenge #10 11) Daily Coding Challenge #11 12) Daily Coding Challenge #12 13) Daily Coding Challenge #13 14) Daily Coding Challenge #14 15) Daily Coding Challenge #15 16) Daily Coding Challenge #16 17) Daily Coding Challenge #17 18) Daily Coding Challenge #18 19) Daily Coding Challenge #19 20) Daily Coding Challenge #20 21) Daily Coding Challenge #21 22) Daily Coding Challenge #22 23) Daily Coding Challenge #23 24) Daily Coding Challenge #24 25) Daily Coding Challenge #25 26) Daily Coding Challenge #26 27) Daily Coding Challenge #27 28) Daily Coding Challenge #28 29) Daily Coding Challenge #29 30) Daily Coding Challenge #30 31) Daily Coding Challenge #31 32) Daily Coding Challenge #32 33) Daily Coding Challenge #33 34) Daily Coding Challenge #34 35) Daily Coding Challenge #35 36) Daily Coding Challenge #36 37) Daily Coding Challenge #37 38) Daily Coding Challenge #38 39) Daily Coding Challenge #39 40) Daily Coding Challenge #40 41) Daily Coding Challenge #41 42) Daily Coding Challenge #42 43) Daily Coding Challenge #43 44) Daily Coding Challenge #44 45) Daily Coding Challenge #45 46) Daily Coding Challenge #46 47) Daily Coding Challenge #47 48) Daily Coding Challenge #48 49) Daily Coding Challenge #49 50) Daily Coding Challenge #50 51) Daily Coding Challenge #51 52) Daily Coding Challenge #52 53) Daily Coding Challenge #53 54) Daily Coding Challenge #54 55) Daily Coding Challenge #55 56) Daily Coding Challenge #56 57) Daily Coding Challenge #57 58) Daily Coding Challenge #58 59) Daily Coding Challenge #59 60) Daily Coding Challenge #60 61) Daily Coding Challenge #61 62) Daily Coding Challenge #62 63) Daily Coding Challenge #63 64) Daily Coding Challenge #64 65) Daily Coding Challenge #65 66) Daily Coding Challenge #66 67) Daily Coding Challenge #67 68) Daily Coding Challenge #68 69) Daily Coding Challenge #69 70) Daily Coding Challenge #70 71) Daily Coding Challenge #71 72) Daily Coding Challenge #72 73) Daily Coding Challenge #73 74) Daily Coding Challenge #74 75) Daily Coding Challenge #75 76) Daily Coding Challenge #76 77) Daily Coding Challenge #77 78) Daily Coding Challenge #78 79) Daily Coding Challenge #79 80) Daily Coding Challenge #80 81) Daily Coding Challenge #81 82) Daily Coding Challenge #82 83) Daily Coding Challenge #83 84) Daily Coding Challenge #84 85) Daily Coding Challenge #85 86) Daily Coding Challenge #86 87) Daily Coding Challenge #87 88) Daily Coding Challenge #88 89) Daily Coding Challenge #89 90) Daily Coding Challenge #90 91) Daily Coding Challenge #91 92) Daily Coding Challenge #92

Posted on by:

wingkwong profile

Wing-Kam

@wingkwong

Consultant by day. Developer by night. AWS certified. Exploring #CloudNative currently.

Discussion

markdown guide