13910 - Branny's naming conventions (1/3)   

Description

This problem is based on "13891 - Polymorphic naming convention conversion".

In this problem, we consider an Integrated Development Environment (IDE) that supports naming convention conversion. We assume that the snake case is the default naming convention:

  • snake case is a naming convention where words are separated by underscores (“_”). For example, my_variable_name or my_function_name are examples of the snake case.

The IDE can convert to a different naming convention according to a programmer’s preference. The IDE can also revert back to the default naming convention for the integration among multiple program files.

Branny, an I2P student, after learning the idea of naming conventions, has also created her own two new naming conventions:

  • castle case is a naming convention where words are separated by underscores (“_”), and each word has its odd index letters be uppercase and even index letters be lowercase (1-based). For example, My_VaRiAbLe_NaMe or My_FuNcTiOn_NaMe are examples of the castle case.
  • number case is a naming convention where words are separated by incremented numbers, which specify the counts of words. For example, my1variable2name or my1function2name are examples of the number case. The numbers would  start at 1.

In this problem, we have the abstract base class ‘Case’ as an interface, which contains two pure virtual member functions:

  • convert: convert to the desired naming convention;
  • revert: revert back to the default naming convention, i.e., the snake case.
#include <string>
using namespace std;

class Case{
    protected:
        bool converted;
        string name;
    public:
        virtual void convert() = 0;
        virtual void revert() = 0;
        virtual ~Case(){}
        Case(string s): converted(false), name(s){}
        void show(ostream &os){
            os << name;
        }
        bool is_converted() const{
            return converted;
        }
};

class CastleCase: public Case{
    public:
        CastleCase(string s): Case(s){}
        void convert();
        void revert();
};

class NumberCase: public Case{
    public:
        NumberCase(string s): Case(s){}
        void convert();
        void revert();
};

 

You are asked to implement the two derived classes ‘CastleCase’ and ‘NumberCase’ by overriding the two pairs of virtual functions, convert and revert, to support the conversion for Branny's preferred naming conventions. :)

Input

The first line contains a string, which can be ‘castle’, ‘number’ or ‘both’.
The second line contains only lowercase letters and underscores, representing the variable name with the snake case.

Constraints:
Testcases 1~3: The first line would be ‘castle’.
Testcases 4~6: The first line would be ‘number’.
Testcases 7~10: The first line would be ‘both’.

Output

The Castle case and the Number case for the input string.

If the first line of input is ‘castle’, print only the castle case.
If the first line of input is ‘number’, print only the number case.
Otherwise, print both of them.

Please refer to the sample output for details.

Sample Input  Download

Sample Output  Download

Partial Judge Code

13910.cpp

Partial Judge Header

13910.h

Tags




Discuss