We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Hiring developers?
  1. Prepare
  2. C++
  3. Introduction
  4. For Loop
  5. Discussions

For Loop

Problem
Submissions
Leaderboard
Discussions
Editorial

    You are viewing a single comment's thread. Return to all comments →

  • ptmkhanh29
    2 months ago+ 0 comments
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */
        int a, b;
        std::vector<std::string> words = {"zero","one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "even", "odd"};
        scanf("%d\n%d", &a, &b);
        for(int i = a; i <= b; i++){
            if(i > 9) {
                if(i%2 == 0) cout << words[10 + i%2] << endl;
                else cout << words[10 + i%2] << endl;
            } 
            else{
                cout << words[i] << endl;
            }
        }
        return 0;
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy