Language: C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned int    U16;
typedef          char   C08;

#define NUM_STR_MAX       11                                     // Contain '\0'
#define OPE_STR_MAX       (NUM_STR_MAX + 7)
#define OPE_COUNT_MAX 2000000
#define INPUT_NUM_MIN 0
#define INPUT_NUM_MAX 2000000000
#define QUEUE_TOP_IDX 0

static void Insert_Num_Void(U16 *U16_Queue_p, U16 *U16_MaxNumIdx, U16 *U16_QueueEndIdx, U16 U16_InputNum);              // Function of insert the num to queue
static void Extract_Num_Void(U16 *U16_Queue_p, U16 *U16_MaxNumIdx, U16 *U16_QueueEndIdx);       // Function of extract the maximum num of queue


/***********************************************************************************
 ++module <main>
 ++outline
        main function
 ++arguments
        <>                      <>                                      []
 ++supp
         <return>
           nothing
 ++end_module
************************************************************************************/
int main(void)
{
        // Valiable declaration
        C08 C08_OpeStr[OPE_STR_MAX]   = {'\0'}; // Operation string ("insert XX", "extract", "end")
        C08 C08_InputNum[NUM_STR_MAX] = {'\0'}; // Input num(C08)
        U16 U16_InputNum    = 0;                                // Input num(U16)
        U16 *U16_Queue_p;                                               // Queue
        U16 U16_MaxNumIdx   = QUEUE_TOP_IDX;    // Max num index of queue
        U16 U16_QueueEndIdx = QUEUE_TOP_IDX;    // Index of queue end
        C08 *C08_IsOpeStrMatch_p;                               // Check the Operation
        U16 U16_i = 0;                                                  // Loop valiable
        
        // Get malloc
        U16_Queue_p = (U16 *)malloc(sizeof(U16) * OPE_COUNT_MAX);
        if(NULL == U16_Queue_p)
        {
                return 1;
        }
        
        // Initialize the queue
        for(U16_i = 0; U16_i < OPE_COUNT_MAX; U16_i++)
        {
                U16_Queue_p[U16_i] = 0;
        }
        // memset(&U16_Queue_p, OPE_COUNT_MAX, 0);
        U16_i = 0;
        
        // Input the operation
        while(U16_i < OPE_COUNT_MAX)
        {
                fgets(C08_OpeStr, OPE_STR_MAX, stdin);
                
                if( NULL != ( C08_IsOpeStrMatch_p = strstr(C08_OpeStr, "insert") ) )                    // Insert the num
                {
                        // Get the number from "C08_OpeStr"
                        strncpy(C08_InputNum, C08_OpeStr + (OPE_STR_MAX - NUM_STR_MAX), NUM_STR_MAX);
                        U16_InputNum = atoi(C08_InputNum);
                        
                        // If the input num is out of the range, do nothing
                        if(INPUT_NUM_MAX < U16_InputNum)
                        {
                                
                        }
                        else
                        {
                                // Insert the num
                                Insert_Num_Void(&U16_Queue_p[QUEUE_TOP_IDX], &U16_MaxNumIdx, &U16_QueueEndIdx, U16_InputNum);
                        }
                }
                else if( NULL != ( C08_IsOpeStrMatch_p = strstr(C08_OpeStr, "extract") ) )              // Extract the num
                {
                        // If the queue is empty, do nothing
                        if(QUEUE_TOP_IDX == U16_QueueEndIdx)
                        {
                                
                        }
                        else
                        {
                                // Extract the num
                                Extract_Num_Void(&U16_Queue_p[QUEUE_TOP_IDX], &U16_MaxNumIdx, &U16_QueueEndIdx);
                        }
                }
                else if( NULL != ( C08_IsOpeStrMatch_p = strstr(C08_OpeStr, "end") ) )                  // End
                {
                        break;
                }
                else
                {
                        // Do nothing
                }
                
                // Reset the operation string
                memset(&C08_OpeStr[0], '\0', sizeof(C08_OpeStr));
                U16_i++;
        }
        
        // Release the queue
        free(U16_Queue_p);
        
        return 0;
}

/***********************************************************************************
 ++module <Insert_Num_Void>
 ++outline
        Insert the num to queue
 ++arguments
        <U16>   <U16_Queue_p>           [Queue]
        <U16>   <U16_MaxNumIdx>         [Index of maximim num]
        <U16>   <U16_QueueEndIdx>       [Index of queue end]
        <U16>   <U16_InputNum>          [Input num]
 ++supp
         <return>
           nothing
 ++end_module
************************************************************************************/
static void Insert_Num_Void(U16 *U16_Queue_p, U16 *U16_MaxNumIdx, U16 *U16_QueueEndIdx, U16 U16_InputNum) {
        U16_Queue_p[*U16_QueueEndIdx] = U16_InputNum;                   // Insert the num
        
        // Update the max num
        if(U16_InputNum > U16_Queue_p[*U16_MaxNumIdx])
        {
                *U16_MaxNumIdx = *U16_QueueEndIdx;
        }
        
        // Update the end index
        (*U16_QueueEndIdx)++;
//        *U16_QueueEndIdx += sizeof(U16);
        
        return;
}


/***********************************************************************************
 ++module <Extract_Num_Void>
 ++outline
        Extract the maximum num of queue  ++arguments
        <U16>   <U16_Queue_p>           [Queue pointer]
        <U16>   <U16_MaxNumIdx>         [Index of maximim num]
        <U16>   <U16_QueueEndIdx>       [Index of queue end]
 ++supp
         <return>
           nothing
 ++end_module
************************************************************************************/
static void Extract_Num_Void(U16 *U16_Queue_p, U16 *U16_MaxNumIdx, U16 *U16_QueueEndIdx) {
        U16 U16_i;
        
        printf("%d\n", U16_Queue_p[*U16_MaxNumIdx]);                           // Disp the max num
        
        // Update the queue
        U16_i = (*U16_MaxNumIdx) + 1;
//        U16_i = (*U16_MaxNumIdx) + sizeof(U16);
        while(1)
        {
                U16_Queue_p[U16_i - 1] = U16_Queue_p[U16_i];
//                U16_Queue_p[U16_i - sizeof(U16)] = U16_Queue_p[U16_i];
                
                if(U16_i == *U16_QueueEndIdx)
                {
                        // Update queue end
                        U16_Queue_p[U16_i] = 0;
                        (*U16_QueueEndIdx)--;
//                        *U16_QueueEndIdx -= sizeof(U16);
                        break;
                }
                U16_i++;
        }
        
        // Update the maximim num
        *U16_MaxNumIdx = QUEUE_TOP_IDX;
        U16_i          = (*U16_MaxNumIdx) + 1;
//        U16_i          = (*U16_MaxNumIdx) + sizeof(U16);
        
        while(1)
        {
                if(U16_Queue_p[U16_i] > U16_Queue_p[*U16_MaxNumIdx])
                {
                        *U16_MaxNumIdx = U16_i;
                }
                
                // If "U16_i" is "U16_QueueEndIdx", break
                // If "U16_i" is not "U16_QueueEndIdx", update "U16_i"
                if(U16_i == *U16_QueueEndIdx)
                {
                        break;
                }
                else
                {
                        U16_i++;
//                        U16_i += sizeof(U16);
                }
        }
        
        return;
}


/*
insert 8
insert 2
extract
insert 10
extract
insert 11
extract
extract
end
*/


________________________________________
差出人: Hayashi，Shinya / 林慎也 <shinya.hayashi.na@hitachi-automotive.co.jp>
送信日時: 2018年5月18日 13:05
宛先: 林　慎也
CC: Hayashi，Shinya / 林慎也
件名: QE活動コード (ALDS1_9_C) 2871699

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long   U32;
typedef                  char   C08;

#define NUM_STR_MAX       11                                    // Contain '\0'
#define OPE_STR_MAX       (NUM_STR_MAX + 7)
#define OPE_COUNT_MAX 2000000
#define INPUT_NUM_MIN 0
#define INPUT_NUM_MAX 2000000000
#define QUEUE_TOP_IDX 0

static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum);              // Function of insert the num to queue
static void Extract_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx);       // Function of extract the maximum num of queue


/***********************************************************************************
 ++module <main>
 ++outline
        main function
 ++arguments
        <>                      <>                                      []
 ++supp
        <return>
          nothing
 ++end_module
************************************************************************************/
int main(void)
{
        // Valiable declaration
        C08 C08_OpeStr[OPE_STR_MAX]   = {'\0'}; // Operation string ("insert XX", "extract", "end")
        C08 C08_InputNum[NUM_STR_MAX] = {'\0'}; // Input num(C08)
        U32 U32_InputNum    = 0;                                // Input num(U32)
        U32 *U32_Queue_p;                                               // Queue
        U32 U32_MaxNumIdx   = QUEUE_TOP_IDX;    // Max num index of queue
        U32 U32_QueueEndIdx = QUEUE_TOP_IDX;    // Index of queue end
        C08 *C08_IsOpeStrMatch_p;                               // Check the Operation
        U32 U32_i = 0;                                                  // Loop valiable

        // Get malloc
        U32_Queue_p = (U32 *)malloc(sizeof(U32) * OPE_COUNT_MAX);
        if(NULL == U32_Queue_p)
        {
                return 1;
        }

        printf("Size = %ld\n", sizeof(U32_Queue_p));
        printf("Size = %d\n", OPE_COUNT_MAX);
        printf("Size = %ld\n", sizeof(U32));

        // Initialize the queue
        for(U32_i = 0; U32_i < OPE_COUNT_MAX; U32_i++)
        {
                U32_Queue_p[U32_i] = 0;
        }
        // memset(&U32_Queue_p, OPE_COUNT_MAX, 0);
        U32_i = 0;

        // Input the operation
        while(U32_i < OPE_COUNT_MAX)
        {
                fgets(C08_OpeStr, OPE_STR_MAX, stdin);

                if( NULL != ( C08_IsOpeStrMatch_p = strstr(C08_OpeStr, "insert") ) )                    // Insert the num
                {
                        printf("insert\n");
                        // Get the number from "C08_OpeStr"
                        strncpy(C08_InputNum, C08_OpeStr + (OPE_STR_MAX - NUM_STR_MAX), NUM_STR_MAX);
                        U32_InputNum = atoi(C08_InputNum);

                        // If the input num is out of the range, do nothing
                        if(INPUT_NUM_MAX < U32_InputNum)
                        {

                        }
                        else
                        {
                                // Insert the num
                                Insert_Num_Void(&U32_Queue_p[QUEUE_TOP_IDX], &U32_MaxNumIdx, &U32_QueueEndIdx, U32_InputNum);
                        }
                }
                else if( NULL != ( C08_IsOpeStrMatch_p = strstr(C08_OpeStr, "extract") ) )              // Extract the num
                {
                        printf("extract\n");
                        // If the queue is empty, do nothing
                        if(QUEUE_TOP_IDX == U32_QueueEndIdx)
                        {

                        }
                        else
                        {
                                // Extract the num
                                Extract_Num_Void(&U32_Queue_p[QUEUE_TOP_IDX], &U32_MaxNumIdx, &U32_QueueEndIdx);
                        }
                }
                else if( NULL != ( C08_IsOpeStrMatch_p = strstr(C08_OpeStr, "end") ) )                  // End
                {
                        printf("end\n");
                        break;
                }
                else
                {
                        printf("else\n");
                        // Do nothing
                }

                // Reset the operation string
                memset(&C08_OpeStr[0], '\0', sizeof(C08_OpeStr));
                U32_i++;
        }

        // Release the queue
        free(U32_Queue_p);

        return 0;
}

/***********************************************************************************
 ++module <Insert_Num_Void>
 ++outline
        Insert the num to queue
 ++arguments
        <U32>   <U32_Queue_p>           [Queue]
        <U32>   <U32_MaxNumIdx>         [Index of maximim num]
        <U32>   <U32_QueueEndIdx>       [Index of queue end]
        <U32>   <U32_InputNum>          [Input num]
 ++supp
        <return>
          nothing
 ++end_module
************************************************************************************/
static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum) {
        U32_Queue_p[*U32_QueueEndIdx] = U32_InputNum;                   // Insert the num
        printf("Queue[%ld] = %ld\n", *U32_QueueEndIdx, U32_Queue_p[*U32_QueueEndIdx]);

        // Update the max num
        if(U32_InputNum > U32_Queue_p[*U32_MaxNumIdx])
        {
                *U32_MaxNumIdx = *U32_QueueEndIdx;
        }

        // Update the end index
//      (*U32_QueueEndIdx)++;

        return;
}


/***********************************************************************************
 ++module <Extract_Num_Void>
 ++outline
        Extract the maximum num of queue  ++arguments
        <U32>   <U32_Queue_p>           [Queue pointer]
        <U32>   <U32_MaxNumIdx>         [Index of maximim num]
        <U32>   <U32_QueueEndIdx>       [Index of queue end]
 ++supp
        <return>
          nothing
 ++end_module
************************************************************************************/
static void Extract_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx) {
        U32 U32_i;

        printf("%ld\n", U32_Queue_p[*U32_MaxNumIdx]);                           // Disp the max num

        // Update the queue
        U32_i = (*U32_MaxNumIdx) + 1;
        while(1)
        {
                U32_Queue_p[U32_i - 1] = U32_Queue_p[U32_i];

                if(U32_i == *U32_QueueEndIdx)
                {
                        // Update queue end
                        U32_Queue_p[U32_i] = 0;
                        (*U32_QueueEndIdx)--;
                        break;
                }
                U32_i++;
        }

        // Update the maximim num
        *U32_MaxNumIdx = QUEUE_TOP_IDX;
        U32_i          = (*U32_MaxNumIdx) + 1;

        while(1)
        {
                if(U32_Queue_p[U32_i] > U32_Queue_p[*U32_MaxNumIdx])
                {
                        *U32_MaxNumIdx = U32_i;
                }

                // If "U32_i" is "U32_QueueEndIdx", break
                // If "U32_i" is not "U32_QueueEndIdx", update "U32_i"
                if(U32_i == *U32_QueueEndIdx)
                {
                        break;
                }
                else
                {
                        U32_i++;
                }
        }

        return;
}


/*
insert 8
insert 2
extract
insert 10
extract
insert 11
extract
extract
end
*/



Compiler output:
main.c:221:1: error: unknown type name '________________________________________'
  221 | ________________________________________
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
main.c:222:7: error: expected '=', ',', ';', 'asm' or '__attribute__' before ':' token
  222 | 差出人: Hayashi，Shinya / 林慎也 <shinya.hayashi.na@hitachi-automotive.co.jp>
      |       ^
main.c:222:52: error: stray '@' in program
  222 | 差出人: Hayashi，Shinya / 林慎也 <shinya.hayashi.na@hitachi-automotive.co.jp>
      |                                                    ^
main.c:223:11: error: invalid suffix "年5月18日" on integer constant
  223 | 送信日時: 2018年5月18日 13:05
      |           ^~~~~~~~~~~~~
main.c:224:9: error: stray '\343' in program
  224 | <U+5B9B><U+5148>: <U+6797><U+3000><U+614E><U+4E5F>
      |                           ^~~~~~~~
main.c:242:29: error: unknown type name 'U32'
  242 | static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum);              // Function of insert the num to queue
      |                             ^~~
main.c:242:47: error: unknown type name 'U32'
  242 | static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum);              // Function of insert the num to queue
      |                                               ^~~
main.c:242:67: error: unknown type name 'U32'
  242 | static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum);              // Function of insert the num to queue
      |                                                                   ^~~
main.c:242:89: error: unknown type name 'U32'
  242 | static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum);              // Function of insert the num to queue
      |                                                                                         ^~~
main.c:243:30: error: unknown type name 'U32'
  243 | static void Extract_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx);       // Function of extract the maximum num of queue
      |                              ^~~
main.c:243:48: error: unknown type name 'U32'
  243 | static void Extract_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx);       // Function of extract the maximum num of queue
      |                                                ^~~
main.c:243:68: error: unknown type name 'U32'
  243 | static void Extract_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx);       // Function of extract the maximum num of queue
      |                                                                    ^~~
main.c:257:5: error: redefinition of 'main'
  257 | int main(void)
      |     ^~~~
main.c:30:5: note: previous definition of 'main' with type 'int(void)'
   30 | int main(void)
      |     ^~~~
main.c: In function 'main':
main.c:262:9: error: unknown type name 'U32'
  262 |         U32 U32_InputNum    = 0;                                // Input num(U32)
      |         ^~~
main.c:263:9: error: unknown type name 'U32'
  263 |         U32 *U32_Queue_p;                                               // Queue
      |         ^~~
main.c:264:9: error: unknown type name 'U32'
  264 |         U32 U32_MaxNumIdx   = QUEUE_TOP_IDX;    // Max num index of queue
      |         ^~~
main.c:265:9: error: unknown type name 'U32'
  265 |         U32 U32_QueueEndIdx = QUEUE_TOP_IDX;    // Index of queue end
      |         ^~~
main.c:267:9: error: unknown type name 'U32'
  267 |         U32 U32_i = 0;                                                  // Loop valiable
      |         ^~~
main.c:270:24: error: 'U32' undeclared (first use in this function); did you mean 'U32_i'?
  270 |         U32_Queue_p = (U32 *)malloc(sizeof(U32) * OPE_COUNT_MAX);
      |                        ^~~
      |                        U32_i
main.c:270:24: note: each undeclared identifier is reported only once for each function it appears in
main.c:270:29: error: expected expression before ')' token
  270 |         U32_Queue_p = (U32 *)malloc(sizeof(U32) * OPE_COUNT_MAX);
      |                             ^
main.c: At top level:
main.c:361:29: error: unknown type name 'U32'
  361 | static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum) {
      |                             ^~~
main.c:361:47: error: unknown type name 'U32'
  361 | static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum) {
      |                                               ^~~
main.c:361:67: error: unknown type name 'U32'
  361 | static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum) {
      |                                                                   ^~~
main.c:361:89: error: unknown type name 'U32'
  361 | static void Insert_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx, U32 U32_InputNum) {
      |                                                                                         ^~~
main.c:390:30: error: unknown type name 'U32'
  390 | static void Extract_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx) {
      |                              ^~~
main.c:390:48: error: unknown type name 'U32'
  390 | static void Extract_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx) {
      |                                                ^~~
main.c:390:68: error: unknown type name 'U32'
  390 | static void Extract_Num_Void(U32 *U32_Queue_p, U32 *U32_MaxNumIdx, U32 *U32_QueueEndIdx) {
      |                                                                    ^~~