DS W8 Array & Queue

Problem ID Title Computer
1846 A Decimal and Octal Conversion (Stack and Queue)
1847 B | Expression Evaluation (Stack and Queue) //PRN
1848 C Same Sequence (Stack and Queue)
1849 D Palindrome (Stack and Queue)
1850 E  | Different Popping Situations (Stack and Queue)
1851 F Knapsack Problem (Stack and Queue)

Problem ID Title After class
1852 A | Queue Combination (Stack and Queue) // Backtracking
1853 B Least Common Multiple (Stack and Queue)
1854 C Reversing the Stack (Stack and Queue)
1855 D Basic Operations of the Stack (Stack and Queue)
1856 E Finding The maximum sum of sub-arrays (stack and queue)
2355 F | multiplication of sparse matrices//code in the textbook

W8 on the machine


1846 Problem A decimal to octal conversion (stack and queue)

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

//1846 Problem A	十进制与八进制的转换(栈和队列)
int main(){
	int t; scanf("%d",&t); printf("%o",t);} 

1847 Problem B Expression Evaluation (Stack and Queue) Link

//REF 年轻过成了秃顶
#include"stdio.h"
#include"string.h"
#define MAX_lenght 10000
typedef struct {double data[MAX_lenght]; int top;} SqStack;//数字的存入。
typedef struct {char data[MAX_lenght]; int top;} SqStackchar;//符号的存入
SqStack S;
SqStackchar Symbol;
void PUSHchar(char t){
  
   
   {
        Symbol.data[Symbol.top]=t;
        Symbol.top++;}}
        
void POPchar(char *t){
  
   
   {
        *t=Symbol.data[Symbol.top-1];
        Symbol.top--;}} 

void PUSH(double e){
  
   
   {
        S.data[S.top]=e;
         S.top++;}}
         
void POP(double *e){
  
   
   {
        *e=S.data[S.top-1];
        S.top--;}}

      
void change(char e){
    static double a,b,c; static char t;
    //如果是 + - 
    if((e=='+'||e=='-') && Symbol.top>0) {t=1;
        while(Symbol.top>0 && t!='('&&t!='['){
            POPchar(&t);
            if((t=='('||t=='[')) break;
            POP(&a); POP(&b);
            switch(t){
                case '+': PUSH(a+b);break;
                case '-': PUSH(b-a);break;
                case 'x': PUSH(a*b);break;
                case '/': PUSH(b/a);break;}
			}
        if(t=='('||t=='[') PUSHchar(t);
        PUSHchar(e);}
    else //如果是 * / 
    if((e=='x'||e=='/') && Symbol.top>0) {t=1;
        while(Symbol.top>0&&t!='('&&t!='['&&t!='+'&&t!='-'){
            POPchar(&t);
            if(t=='('||t=='['||t=='+'||t=='-') break;
            POP(&a); POP(&b);
            switch(t) {
  

Guess you like

Origin blog.csdn.net/qq_51314244/article/details/130068543