1667 - I2P(II)2019_Yang_hw5 Scoreboard

Time

2019/04/26 16:00:00 2019/05/10 12:00:00

Clarification

# Problem Asker Description Reply Replier Reply Time For all team

# Problem Pass Rate (passed user / total user)
10997 Queue
11417 String Operation
11421 Palindrome

10997 - Queue   

Description

A queue is an abstract data type that serves as a collection of elements, where nodes are removed only from the head of the queue and are inserted only at the tail of the queue. Two principal operations can be used to manipulate a queue: enqueue, which inserts an element at the tail, and dequeue, which removes the element at the head of the collection.

Let’s see how the queue data structure can be realized in C++.We have an approach to implement queue: linked list. Thus, we define a class as follows:

 class List_queue {

    public:

        List_queue();

        ~List_queue();

        void enqueue(const int &);

        void dequeue();

        void print();

    private:

        ListNode *head;

        ListNode *tail;

};

where List_queue implements the queue data structure.

REQUIREMENTS:

Implement the constructor, destructor, enqueue(), dequeue() and print() member functions of the List_queue class.

Note:

1.This problem involves three files.

  • function.h: Class definitions.
  • function.cpp: Member-function definitions.
  • main.cpp: A driver program to test your class implementation.

You will be provided with main.cpp and function.h, and asked to implement function.cpp.

function.h

main.cpp

2.For OJ submission:

       Step 1. Submit only your function.cpp into the submission block.

       Step 2. Check the results and debug your program if necessary.

Input

There are three kinds of commands:

  • “enqueue integerA” represents inserting an element with int value A at the tail of the queue.
  • “dequeue” represents removing the element at the head of the queue.
  • “print” represents showing the current content of the queue.

Each command is followed by a new line character.

Input terminated by EOF.

Output

The output should consist of the current state of the queue.

When the queue is empty, you don’t need to print anything except a new line character.

Sample Input  Download

Sample Output  Download

Partial Judge Code

10997.cpp

Partial Judge Header

10997.h

Tags

10402HW6



Discuss




11417 - String Operation   

Description

Given a set of strings, perform the operations according to the following commands, and output the final result of the given set of strings.

 

Commands:

s n m: Swap the nth string and the mth string.

i n m: Insert the mth string at the tail of the nth string.

si n m: Swap the specified strings first, and then insert.

is n m: Insert first, and then swap the two specified strings.

e: Exit.

 

Consider a set of strings:

ab

cd

ef

And a sequence of commands:

s 0 1

i 1 2

The result will be:

cd

abef

ef

 

You will be provided with main.cpp and function.h, and asked to implement function.cpp.

Input

The first line is an integer N indicating the number of input strings.

The following N lines each contains one input string.

Starting from the N+2th line will be a sequence of commands.

Output

Output the final result of the input strings.

Sample Input  Download

Sample Output  Download

Partial Judge Code

11417.cpp

Partial Judge Header

11417.h

Tags




Discuss




11421 - Palindrome   

Description

Palindrome is a string that is identical to its reverse, like "level" or "aba". Check whether a given string is a palindrome or not. 

Create a class SimpleString that manipulates a given string of characters. This class contains proper constructor functions (default constructor and copy constructor) and supports the following operations (in the form of member functions):

  • Ÿ   Overloading the assignment operator (=) to assign one given SimpleString object to the current SimpleStringobject.
  • Ÿ   Reversing the string which is stored in the SimpleString object.
  • Ÿ   Overloading the relational operator (==) to check whether two strings, which are stored in two SimpleStringobjects, are the same or not.
  • Ÿ   Overloading the operator (>>) to input the string into the SimpleString object.
  • Ÿ   Overloading the operator (<<) to ouput the string from the SimpleString object.

To check if a given string is a palindrome, we have provided another class PalindromeChecker as follows:

class PalindromeChecker

{

public:

    PalindromeChecker(const SimpleString &s)

    {

        str = s;

        rev = s;

        rev.reverse();

    };

    void isPalindrome()

    {

        if(rev == str)

            std::cout << "Yes\n";

        else

            std::cout << "No\n";

    };

private:

    SimpleString str;

    SimpleString rev;

};

Note:

This problem involves three files.

  •   function.h: Class definition of SimpleString.
  •   function.cpp: Member-function definitions of SimpleString.
  •   main.cpp: A driver program to test your class implementation.

You will be provided with main.cpp and function.h, and asked to implement function.cpp.

Note that you don’t need to implement class PalindromeChecker

function.h

#ifndef SIMPLESTRING_H
#define SIMPLESTRING_H
#include <iostream>
using namespace std;

class SimpleString
{
    friend std::ostream &operator<<(std::ostream &, const SimpleString &);
    friend std::istream &operator>>(std::istream &, SimpleString &);
public:
    SimpleString():size(0),ptr(NULL){} // default constructor
    SimpleString( const SimpleString & ); // copy constructor
    ~SimpleString(); // destructor
    const SimpleString &operator=( const SimpleString & ); // assignment operator
    bool operator==( const SimpleString & ) const; // equality operator
    void reverse(); // reverse the string
private:
    size_t size; // pointer-based string size
    char *ptr; // pointer to first element of pointer-based string
}; // end class SimpleString
class PalindromeChecker
{
public:
    PalindromeChecker(const SimpleString &s)
    {
        str = s;
        rev = s;
        rev.reverse();
    };
    void isPalindrome()
    {
        if(rev == str)
            std::cout << "Yes\n";
        else
            std::cout << "No\n";
    };
private:
    SimpleString str;
    SimpleString rev;
};

#endif

main.cpp

#include <iostream>
#include "function.h"

using namespace std;

int main()
{
    SimpleString s;
    while(cin>>s){
        if(cin.eof())break;

        PalindromeChecker c(s);
        c.isPalindrome();
        cout<<s<<endl;
    }

    return 0;
}

Input

The input consists of multiple lines. Each line contains a string. The length of each string is less than 100000. The number of test case is less than 1000. 

Output

For each test case, output "Yes" or "No" and the string . 

Sample Input  Download

Sample Output  Download

Partial Judge Code

11421.cpp

Partial Judge Header

11421.h

Tags




Discuss