if-else statement

On Christmas, in the evening, there were three flowers in the window, from left to right: geranium, crocus and violet. Every morning Masha cleans the dust and changes position of the right flower with central one. In the afternoon, Tanya waters the flowers and swaps left and central flowers. Print the order of the flowers after k days, at night.

Input

The first line contains a number of test cases m (1 ≤ m ≤ 12). Each of the following m lines contains the number of days k (1 ≤ k ≤ 1000).

Output

Print for each test case in a separate line three Latin letters 'G', 'C' and 'V' (capital letters, no spaces) representing the order of flowers in k days (from left to right). Here G stands for geranium, C for crocus and V for violet.

Time limit 1 second

Memory limit 64 MiB
Input example
2
1
5
Output example
VGC
CVG


can anyone help?
Last edited on
There is no ifs in that job. Just swap letters as many times as you need to.


However, when you do test that, you perhaps notice a pattern. The output can be computed without swapping of values.
can anyone help?
Don't post homework questions
Programmers are good at spotting homework questions; most of us have done them ourselves. Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.

Show that you've put in some effort before asking for help. I'd recommend simulating each day using pen and paper.
Example so you get the idea:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>

int main()
{
    std::string flowers[3] = { "geranium", "crocus", "violet" };
    int numDays = 0;

    std::cout << "How many days have passed: " << std::flush;
    while (!(std::cin >> numDays) || numDays < 1)
    {
        std::cin.clear();
        std::cin.ignore(1000000, '\n');
        std::cout << "Please enter positive value: " << std::flush;
    }

    if (numDays % 3 == 1)
    {
        std::string temp = flowers[1];
        flowers[1] = flowers[2];
        flowers[2] = temp;
    }
    else if (numDays % 3 == 2)
    {
        std::string temp = flowers[1];
        flowers[1] = flowers[0];
        flowers[0] = temp;
    }

    std::cout << "\n\n";
    for (const std::string &s : flowers)
    {
        std::cout << s << "     " << std::flush;
    }

    std::cin.ignore();
    std::cin.get();

    return 0;
}

Compiles and works.
Last edited on
#include <iostream>
using namespace std;
int main()
{
int k,m;
cin>>m;
while(m--) {
cin>>k;
if(k%3==0) cout<<"GCV"<<endl;
else if(k%3==1)cout<<"VGC"<<endl;
else if(k%3==2)cout<<"CVG"<<endl;

}

}

it's 100 %
closed account (48T7M4Gy)
http://www.cplusplus.com/forum/beginner/203377/
Topic archived. No new replies allowed.