The C programming language (second edition,KR) exercise(CHAPTER 4)

      E x c e r c i s e 4 − 1 Excercise\quad 4-1 Excercise41

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
int strindex(char s[],char t[]);
int strrindex(char s[],char t[]);int main(void) 
{char s[100]="qwoulddfsdfdsgdsgdsgdsouldasdasdasd";char t[100]="ould";	int l_index=strindex(s,t);int r_index=strrindex(s,t);	printf("l_index=%d\n",l_index);	printf("r_index=%d\n",r_index);		return 0;
}int strindex(char s[],char t[])
{int i,j,k;for(i=0;s[i]!='\0' ;i++){for(j=i,k=0;t[k]!='\0' && s[j]==t[k];j++,k++);if((k>0)&&(t[k]=='\0'))return i;}		return -1;
}int strrindex(char s[],char t[])
{int i,j,k;int t_len=strlen(t);int s_len=strlen(s);if(t_len>s_len){return -1;				}else{for(i=s_len-t_len;i>=0 ;i--){for(j=i,k=0;t[k]!='\0' && s[j]==t[k];j++,k++);if((k>0)&&(t[k]=='\0'))return i;	    	}		return -1;}
}

      E x c e r c i s e 4 − 2 Excercise\quad 4-2 Excercise42:输出如图1所示。

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>double atof_myself(char s[]);int main(void) 
{char s1[100]="123.789e1";char s2[100]="123456123456.789e-10";	char s3[100]="123.789";		double d1=atof_myself(s1);double d2=atof_myself(s2);double d3=atof_myself(s3);	printf("d1=%lf\n",d1);printf("d2=%lf\n",d2);	printf("d3=%lf\n",d3);		return 0;
}double atof_myself(char s[])
{double val,power,power_more;int i,sign,sign_more,power_more_index;for(i=0;isspace(s[i]);i++);sign=(s[i]=='-')? -1:1;if((s[i]=='-')||(s[i]=='+')){i++;}	for(val=0.0;isdigit(s[i]);i++){val=10.0*val+(s[i]-'0');		}	if(s[i]=='.'){i++;}for(power=1.0;isdigit(s[i]);i++){val=10.0*val+(s[i]-'0');power *=10.0;		}	if((s[i]=='e') ||(s[i]=='E')){i++;sign_more=(s[i]=='-')? -1:1;if((s[i]=='-')||(s[i]=='+')){i++;}	for(power_more_index=0;isdigit(s[i]);i++){power_more_index=10*power_more_index+(s[i]-'0');	}power_more=1.0;for(i=0;i<power_more_index;i++){power_more=power_more*10.0;			}	if(sign_more==-1){return ((sign * val/power)/power_more);    	    		    	}else{return ((sign * val/power)*power_more);  	}		}else{return (sign * val/power); 	   	}	
}
图1.

      E x c e r c i s e 4 − 3 Excercise\quad 4-3 Excercise43

#include <stdio.h>
#include <stdlib.h>   /* for atof() */
#include <math.h>     /* for fmod() */#define MAXOP 100     /* max size of operand or operator */
#define NUMBER '0'    /* signal that a number was found */int getop(char []);
void push(double);
double pop(void);/* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;case '\n':printf("\t%.8g\n", pop());break;				 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && c != '.' && c != '-'){	return c; /* not a number */}if(c == '-'){i = 0;			c = getch();	s[++i] = c;			}else{i = 0;				}if (isdigit(c)) /* collect integer part */while (isdigit(s[++i] = c = getch()));if (c == '.') /* collect fraction part */while (isdigit(s[++i] = c = getch()));s[i] = '\0';if (c != EOF){		ungetch(c);}if (i == 1 && s[0] == '-') // if s[0] == '-' && s[1] == '\0', return minus operatorreturn '-';	return NUMBER;
}#define BUFSIZE 100char buf[BUFSIZE];   /* buffer for ungetch */
int bufp = 0;        /* next free position in buf */int getch(void)      /* get a (possibly pushed-back) character */
{return (bufp > 0) ? buf[--bufp] : getchar();
}void ungetch(int c) /* push character back on input */
{if (bufp >= BUFSIZE)printf("ungetch: too many characters\n");elsebuf[bufp++] = c;
}

      E x c e r c i s e 4 − 4 Excercise\quad 4-4 Excercise44

#include <stdio.h>
#include <stdlib.h>   /* for atof() */
#include <math.h>     /* for fmod() */#define MAXOP 100     /* max size of operand or operator */
#define NUMBER '0'    /* signal that a number was found */int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();/* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/				 case '\n':printf("\t%.8g\n", pop());break;				 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if(sp > 0){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && c != '.' && c != '-'){	return c; /* not a number */}if(c == '-'){i = 0;			c = getch();	s[++i] = c;			}else{i = 0;				}if (isdigit(c)) /* collect integer part */while (isdigit(s[++i] = c = getch()));if (c == '.') /* collect fraction part */while (isdigit(s[++i] = c = getch()));s[i] = '\0';// if (c != EOF)// {		// ungetch(c);// }if (i == 1 && s[0] == '-') // if s[0] == '-' && s[1] == '\0', return minus operatorreturn '-';	return NUMBER;
}#define BUFSIZE 100char buf[BUFSIZE];   /* buffer for ungetch */
int bufp = 0;        /* next free position in buf */int getch(void)      /* get a (possibly pushed-back) character */
{return (bufp > 0) ? buf[--bufp] : getchar();
}void ungetch(int c) /* push character back on input */
{if (bufp >= BUFSIZE)printf("ungetch: too many characters\n");elsebuf[bufp++] = c;
}

      E x c e r c i s e 4 − 5 Excercise\quad 4-5 Excercise45

#include <stdio.h>
#include <stdlib.h>  
#include <math.h>   #define MAXOP 100     /* max size of operand or operator */
#define NUMBER '0'    /* signal that a number was found */int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();/* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/
/****************************************************/				 case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;				
/****************************************************/				 case '\n':printf("\t%.8g\n", pop());break;				 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if(sp > 0){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && c != '.' && c != '-'){	return c; /* not a number */}if(c == '-'){i = 0;			c = getch();	s[++i] = c;			}else{i = 0;				}if (isdigit(c)) /* collect integer part */while (isdigit(s[++i] = c = getch()));if (c == '.') /* collect fraction part */while (isdigit(s[++i] = c = getch()));s[i] = '\0';// if (c != EOF)// {		// ungetch(c);// }if (i == 1 && s[0] == '-') // if s[0] == '-' && s[1] == '\0', return minus operatorreturn '-';	return NUMBER;
}#define BUFSIZE 100char buf[BUFSIZE];   /* buffer for ungetch */
int bufp = 0;        /* next free position in buf */int getch(void)      /* get a (possibly pushed-back) character */
{return (bufp > 0) ? buf[--bufp] : getchar();
}void ungetch(int c) /* push character back on input */
{if (bufp >= BUFSIZE)printf("ungetch: too many characters\n");elsebuf[bufp++] = c;
}

      E x c e r c i s e 4 − 6 Excercise\quad 4-6 Excercise46:其实这一题的意图似乎还是很模糊的,我这里的做法是提供26个变量(分别对应26个小写英文字母),然后再提供一个数组用来存储这26个变量的值。如果要对某个变量赋值可以类似 x = n n n . n n n x=nnn.nnn x=nnn.nnn来操作,其中 x x x表示26个小写英文字母中的任何一个, n n n . n n n nnn.nnn nnn.nnn表示即将赋值给变量的值,这个值可以为负数,负数的话在最前面需要加上 − - ,比如 − n n n . n n n -nnn.nnn nnn.nnn。某个变量在参与运算之前需要先进行赋值操作,否则可能拿到的是默认值 0.0 0.0 0.0,变量参加运算的一个例子为 a 8 + a8+ a8+实际是变量 a a a的值和8进行加法运算。这里还记录了最近赋值或参与运算的是那个变量,并且 _ \_ _符号对应的命令操作会将这个最近赋值或参与运算的变量以及对应的值打印出来。

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;
/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	
/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;char setVar = FALSE;i = 0;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = getch()) == '='){			setVar = TRUE;c = getch();s[++i] = c;		}else{if (c != EOF){		ungetch(c);}return GETVARIABLE;}}if(c == '-'){		c = getch();	s[++i] = c;			}if (isdigit(c)) /* collect integer part */{	while (isdigit(s[++i] = c = getch()));}if (c == '.') /* collect fraction part */{	while (isdigit(s[++i] = c = getch()));}s[i] = '\0';if (c != EOF){		ungetch(c);}
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}#define BUFSIZE 100char buf[BUFSIZE];   /* buffer for ungetch */
int bufp = 0;        /* next free position in buf */int getch(void)      /* get a (possibly pushed-back) character */
{return (bufp > 0) ? buf[--bufp] : getchar();
}void ungetch(int c) /* push character back on input */
{if (bufp >= BUFSIZE)printf("ungetch: too many characters\n");elsebuf[bufp++] = c;
}

      E x c e r c i s e 4 − 7 Excercise\quad 4-7 Excercise47

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;
/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	
/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;char setVar = FALSE;i = 0;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = getch()) == '='){			setVar = TRUE;c = getch();s[++i] = c;		}else{if (c != EOF){		ungetch(c);}return GETVARIABLE;}}if(c == '-'){		c = getch();	s[++i] = c;			}if (isdigit(c)) /* collect integer part */{	while (isdigit(s[++i] = c = getch()));}if (c == '.') /* collect fraction part */{	while (isdigit(s[++i] = c = getch()));}s[i] = '\0';if (c != EOF){		ungetch(c);}
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}#define BUFSIZE 100char buf[BUFSIZE];   /* buffer for ungetch */
int bufp = 0;        /* next free position in buf */int getch(void)      /* get a (possibly pushed-back) character */
{return (bufp > 0) ? buf[--bufp] : getchar();
}void ungetch(int c) /* push character back on input */
{if (bufp >= BUFSIZE)printf("ungetch: too many characters\n");elsebuf[bufp++] = c;
}/*ungets() actually takes a little bit of thought.  Should thefirst character in "s" be sent to ungetch() first, or shouldit be sent last?  I assumed that most code calling getch()would be of this form:char array[...];int i;   while (...) {array[i++] = getch();}                  In such cases, the same code might call ungets() as:ungets(array);and expect to repeat the while loop to get the same stringback.  This requires that the last character be sent firstto ungetch() first, because getch() and ungetch() work with a stack.     To answer K&R2's additional question for this problem,it's usually preferable for something like ungets() to justbuild itself on top of ungetch().  This allows us to change ungetch() and getch() in the future, perhaps to use a linked list instead, without affecting ungets().
*/ 
void ungets(const char *s)
{    int i, len;len = strlen(s);if(BUFSIZE - bufp >= len)  // ungets() must do its own bounds checking{for(i = strlen(s) - 1; i >= 0; i--)ungetch(s[i]);}elseprintf("error: insufficient space in buffer, can't execute ungets()\n");
}

      E x c e r c i s e 4 − 8 Excercise\quad 4-8 Excercise48

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;
/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	
/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;char setVar = FALSE;i = 0;while ((s[0] = c = getch()) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = getch()) == '='){			setVar = TRUE;c = getch();s[++i] = c;		}else{if (c != EOF){		ungetch(c);}return GETVARIABLE;}}if(c == '-'){		c = getch();	s[++i] = c;			}if (isdigit(c)) /* collect integer part */{	while (isdigit(s[++i] = c = getch()));}if (c == '.') /* collect fraction part */{	while (isdigit(s[++i] = c = getch()));}s[i] = '\0';if (c != EOF){		ungetch(c);}
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}char buf=EOF;   /* buffer for ungetch */int getch(void)      /* get a (possibly pushed-back) character */
{return (buf!=EOF) ? buf : getchar();
}void ungetch(int c) /* push character back on input */
{if (buf!=EOF)printf("ungetch: too many characters\n");elsebuf = c;
}

      E x c e r c i s e 4 − 9 Excercise\quad 4-9 Excercise49

      E x c e r c i s e 4 − 10 Excercise\quad 4-10 Excercise410

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */
#define MAXLINE 1000        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	
int getline(char s[], int lim);/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /*********************************/
char line[MAXLINE];
int line_i;
/*********************************/
/* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while (getline(line, MAXLINE) != 0){line_i=0;while ((type = getop(s)) != '\0') {switch (type) {case NUMBER:push(atof(s));break;/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>
int getch(void);
void ungetch(int);/* getop: get next character or numeric operand */
int getop(char s[])
{int i, c;char setVar = FALSE;i = 0;while ((s[0] = c = line[line_i++]) == ' ' || c == '\t');s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = line[line_i++]) == '='){			setVar = TRUE;c = line[line_i++];s[++i] = c;		}else{if (c != '\0'){		line_i=line_i-1;}return GETVARIABLE;}}if(c == '-'){		c = line[line_i++];	s[++i] = c;			}if (isdigit(c)) /* collect integer part */{	while (isdigit(s[++i] = c = line[line_i++]));}if (c == '.') /* collect fraction part */{	while (isdigit(s[++i] = c = line[line_i++]));}s[i] = '\0';if (c != '\0'){		line_i=line_i-1;}
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}// /* getop: get next character or numeric operand */
// int getop(char s[])
// {// int i, c;// char setVar = FALSE;// i = 0;// while ((s[0] = c = getch()) == ' ' || c == '\t');// s[1] = '\0';// if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-')// {	// return c; /* not a number */// }// if (c >= 'a' && c <= 'z')// {// last_recent=c;
// /* get next char and check if it was an equal symbol.*/ 		// if ((s[++i] = c = getch()) == '=')// {			// setVar = TRUE;// c = getch();// s[++i] = c;		// }// else// {// if (c != EOF)// {		// ungetch(c);// }// return GETVARIABLE;// }// }// if(c == '-')// {		// c = getch();	// s[++i] = c;			// }// if (isdigit(c)) /* collect integer part */// {	// while (isdigit(s[++i] = c = getch()));// }// if (c == '.') /* collect fraction part */// {	// while (isdigit(s[++i] = c = getch()));// }// s[i] = '\0';// if (c != EOF)// {		// ungetch(c);// }
// /* if s[0] == '-' && s[1] == '\0', return minus operator */	// if (i == 1 && s[0] == '-') // return '-';	// if (setVar)// {	// return SETVARIABLE;	// }		// return NUMBER;
// }/* getline:  get line into s, return length */
int getline(char s[], int lim)
{int c, i;i = 0;while (--lim > 0 && (c = getchar()) != EOF && c != '\n')s[i++] = c;if (c == '\n')s[i++] = c;s[i] = '\0';return i;
}

      E x c e r c i s e 4 − 11 Excercise\quad 4-11 Excercise411

#include <stdio.h>
#include <stdlib.h> 
#include <ctype.h>
#include <math.h>
#include <string.h> #define MAXOP     100     /* max size of operand or operator */
#define NUMBER    '0'     /* signal that a number was found */
#define SETVARIABLE 's'   /* signal that a variable is being assigned */
#define GETVARIABLE 'g'   /* signal that a variable is being retrieved */
#define NUMVARS 26        /* number of variables supported (a-z) */enum boolean {FALSE, TRUE};int getop(char []);
void push(double);
double pop(void);
void showTop(void);
void duplicate(void);
void swapItems(void);
void clearStack();
void view_stack();	/* initially as space such that malformed use of '=' won't cause segfaults */
char last_recent = ' '; 
/* array to store the double values for variables. 
Supports variables a through z (lower case). Initial value is 0*/
double varVals[NUMVARS] = {0.0}; /* reverse Polish calculator */
int main()
{int type;double op2;char s[MAXOP];while ((type = getop(s)) != EOF) {switch (type) {case NUMBER:push(atof(s));break;
/****************************************************/				 case SETVARIABLE:if (strlen(s) > 2 && s[1] == '='){int v = s[0];           /* stores variable */int i = 1;              /* start at 1 since while loop needed ++i for a few reasons */while (s[++i] != '\0')  /* this removes the variable name= part of s e.g. if s == "a=123.45" after loop s == "123.45" */s[i - 2] = s[i];    /* shifts chars two to the left by 2 */s[i - 2] = '\0';        /* since '\0' isn't copied, terminate string manually */varVals[v - 'a'] = atof(s); /* convert string to double and store it in array */}elseprintf("error: set variable length too small or incorrectly formatted (%s)\n", s);break;case GETVARIABLE:push(varVals[s[0] - 'a']);  /* convert the variable name to stored value */break;	
/****************************************************/				 case '+':push(pop() + pop());break;case '*':push(pop() * pop());break;case '-':op2 = pop();push(pop() - op2);break;case '/':op2 = pop();if (op2 != 0.0)push(pop() / op2);elseprintf("error: zero divisor\n");break;case '%':op2 = pop();if (op2 != 0.0)push(fmod(pop(),op2));elseprintf("error: zero divisor\n");break;
/****************************************************/				 case '?':showTop();break;case '#':duplicate();break;case '~':swapItems();break;case '!':clearStack();	break;				
/****************************************************/case '$':push(sin(pop()));break;case '@':push(exp(pop()));break;case '^':op2 = pop();push(pow(pop(),op2));break;									// case '\n':// printf("\t%.8g\n", pop());// break;case '\n':view_stack();break;	case '_':printf("The last recently used variable is %c=%8g\n",last_recent, varVals[last_recent-'a']);break;					 default:printf("error: unknown command %s\n", s);break;}}return 0;
}#define MAXVAL 100   /* maximum depth of val stack */
int sp = 0;          /* next free stack position */
double val[MAXVAL];  /* value stack *//* push: push f onto value stack */
void push(double f)
{if (sp < MAXVAL)val[sp++] = f;elseprintf("error: stack full, can't push %g\n", f);
}/* pop: pop and return top value from stack */
double pop(void)
{if (sp > 0)return val[--sp];else {printf("error: stack empty\n");return 0.0;}
}/* push: push f onto value stack */
void view_stack()
{int i=sp;if (sp >0){while(i>0){printf("view_stack:%8g\n",val[i-1]);i=i-1;}}elseprintf("view_stack:Stack is empty\n");
}/**********************************************************/
void showTop(void)
{if(sp > 0)printf("Top of stack contains: %8g\n", val[sp-1]);elseprintf("The stack is empty!\n");
}void duplicate(void)
{double temp = 0.0;	if((sp > 0) &&(sp < MAXVAL)){temp = pop();push(temp);push(temp);				}elseprintf("The stack is empty!\n");	}void swapItems(void)
{double item1 = 0.0;double item2 = 0.0;	if(sp >= 2){item1 = pop();item2 = pop();push(item1);push(item2);			}elseprintf("The stack is empty!\n");	
}/* pop only returns a value if sp is greater than zero. So setting the
stack pointer to zero will cause pop to return its error */void clearStack(void)
{sp = 0;
}/**********************************************************/#include <ctype.h>/* getop: get next character or numeric operand */
int getop(char s[])
{int i;static int c=EOF;	static int unget_flag=0;		char setVar = FALSE;i = 0;if(unget_flag==1){if((c== ' ') || (c == '\t')){while ((s[0] = c = getchar()) == ' ' || c == '\t');	    		    	}	else{s[0] = c;			}unget_flag=0;}else{while ((s[0] = c = getchar()) == ' ' || c == '\t');				}s[1] = '\0';if (!isdigit(c) && !isalpha(c) && c != '.' && c != '-'){	return c; /* not a number */}if (c >= 'a' && c <= 'z'){last_recent=c;
/* get next char and check if it was an equal symbol.*/ 		if ((s[++i] = c = getchar()) == '='){			setVar = TRUE;c = getchar();s[++i] = c;		}else{if (c != EOF){		unget_flag=1;}			return GETVARIABLE;}}if(c == '-'){		c = getchar();	s[++i] = c;			}if (isdigit(c)) /* collect integer part */{	while (isdigit(s[++i] = c = getchar()));}if (c == '.') /* collect fraction part */{	while (isdigit(s[++i] = c = getchar()));}	s[i] = '\0';if (c != EOF){		unget_flag=1;}		
/* if s[0] == '-' && s[1] == '\0', return minus operator */	if (i == 1 && s[0] == '-') return '-';	if (setVar){	return SETVARIABLE;	}		return NUMBER;
}

      E x c e r c i s e 4 − 12 Excercise\quad 4-12 Excercise412

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>void itoa_myself(int n, char s[], int minmum);int main(void) 
{char buffer[100];printf("INT_MIN: %d\n", INT_MIN);itoa_myself(INT_MIN, buffer,25);printf("Buffer : %s\n", buffer);printf("\\*******************************\\\n");   printf("378\n");itoa_myself(378, buffer,25);printf("Buffer : %s\n", buffer);printf("\\*******************************\\\n");   printf("-873\n");itoa_myself(-873, buffer,25);printf("Buffer : %s\n", buffer);return 0;
}void itoa_myself(int n, char s[],int minmum) 
{static int i=0;static int recur_num=0;	recur_num=recur_num+1;if(n<0){s[i++] = '-';		}if(n/10){itoa_myself(abs(n/10), s,minmum); } s[i++] = abs(n % 10) + '0';	if(i>minmum){printf("Elements overflow\n");}recur_num=recur_num-1;if(recur_num==0){	s[i] = '\0';	i=0;recur_num=0;	    		}
}

      E x c e r c i s e 4 − 13 Excercise\quad 4-13 Excercise413

#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>void itoa_myself(int n, char s[], int minmum);
void reverse(char s[]);int main(void) 
{char buffer[100];printf("INT_MIN: %d\n", INT_MIN);itoa_myself(INT_MIN, buffer,25);printf("Buffer : %s\n", buffer);return 0;
}void itoa_myself(int n, char s[], int minmum) 
{int i, sign;sign = n;i = 0;do {s[i++] = abs(n % 10) + '0';} while ( n /= 10 );if (sign < 0)s[i++] = '-';while(i<minmum){s[i++] = ' ';		}	s[i] = '\0';reverse(s);
}void reverse(char s[]) 
{int c;	static int first_flag=1;		static int i=0;	static int j=0;if(first_flag==1){first_flag=0;j=strlen(s)-1;}if ( i < j ) {c = s[i];s[i] = s[j];s[j] = c;i=i+1;j=j-1;reverse(s);}
}

      E x c e r c i s e 4 − 14 Excercise\quad 4-14 Excercise414

#include <stdio.h>#define swap(t,x,y) {              \t temp=x;  \x=y;       \y=temp;    \}int main(void) 
{int a=6;int b=9;swap(int,a,b)printf("a=%d,b=%d\n", a,b);return 0;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.hqwc.cn/news/637673.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

m个人的成绩存放在score数组中,请编写函数fun,它的功能是:将低于平均分的人数作为函数值返回,将低于平均分的分数放在below所指的数组中。

本文收录于专栏:算法之翼 https://blog.csdn.net/weixin_52908342/category_10943144.html 订阅后本专栏全部文章可见。 本文含有题目的题干、解题思路、解题思路、解题代码、代码解析。本文分别包含C语言、C++、Java、Python四种语言的解法和详细的解析。 题干 m个人的成绩…

linux的编译器vim

vim简介 之前我们在win下写代码&#xff0c;都是下载一些编译器VS/eclipse等 他们不仅可以写代码&#xff0c;还可以实现代码的运行调试&#xff0c;开发。这样的编译器叫做集成编译器 而linux中虽然也有这样的编译器&#xff0c;但不管是从下载&#xff0c;还是使用中都会显…

同旺科技 USB TO SPI / I2C适配器读写24LC128--读写

所需设备&#xff1a; 1、USB 转 SPI I2C 适配器&#xff1b;内附链接 2、24LC128芯片&#xff1b; 适应于同旺科技 USB TO SPI / I2C适配器专业版&#xff1b; 专业版配套软件更新&#xff1b; 直接读取HEX文件&#xff0c;自动完成文件解析&#xff1b; 支持芯片&#xf…

C++的初步知识——命名空间,缺省参数,重载函数

C 首先写一段代码&#xff1a; #include <stdio.h>int main() {printf("Hello world\n");return 0; }这段C语言代码在cpp文件中仍可运行。我们了解C是兼容C语言的&#xff0c;C的关键字中就包含了C语言的关键字和自身的关键字。关于关键字&#xff0c;我们简…

Elasticsearch进阶篇(三):ik分词器的使用与项目应用

ik分词器的使用 一、下载并安装1.1 已有作者编译后的包文件1.2 只有源代码的版本1.3 安装ik分词插件 二、ik分词器的模式2.1 ik_smart演示2.2 ik_max_word演示2.3 standard演示 三、ik分词器在项目中的使用四、ik配置文件4.1 配置文件的说明4.2 自定义词库 五、参考链接 一、下…

C++ | Leetcode C++题解之第42题接雨水

题目&#xff1a; 题解&#xff1a; class Solution { public:int trap(vector<int>& height) {int n height.size();if (n 0) {return 0;}vector<int> leftMax(n);leftMax[0] height[0];for (int i 1; i < n; i) {leftMax[i] max(leftMax[i - 1], he…

8.idea中一个服务启动多实例

指定一个新的端口-Dserver.port8082

T1级,生产环境事故—Shell脚本一键备份K8s的YAML文件

大家好&#xff0c;我叫秋意零。 最近对公司进行日常运维工作时&#xff0c;出现了一个 T1 级别事故。导致公司的“酒云网”APP的无法使用。我和我领导一起搞了一个多小时&#xff0c;业务也停了一个多小时。 起因是&#xff1a;我的部门直系领导&#xff0c;叫我**删除一个 …

软件杯 深度学习实现行人重识别 - python opencv yolo Reid

文章目录 0 前言1 课题背景2 效果展示3 行人检测4 行人重识别5 其他工具6 最后 0 前言 &#x1f525; 优质竞赛项目系列&#xff0c;今天要分享的是 &#x1f6a9; **基于深度学习的行人重识别算法研究与实现 ** 该项目较为新颖&#xff0c;适合作为竞赛课题方向&#xff0c…

MultiHeadAttention在Tensorflow中的实现原理

前言 通过这篇文章&#xff0c;你可以学习到Tensorflow实现MultiHeadAttention的底层原理。 一、MultiHeadAttention的本质内涵 1.Self_Atention机制 MultiHeadAttention是Self_Atention的多头堆嵌&#xff0c;有必要对Self_Atention机制进行一次深入浅出的理解&#xff0c;这…

牛客NC357 矩阵第K小【中等 堆 Java、Go、PHP】

题目 题目链接&#xff1a; https://www.nowcoder.com/practice/c754e7a920614cba9b8b692ba9b20b5d 核心 堆&#xff0c;或者叫优先级队列参考答案Java import java.util.*;public class Solution {/*** 代码中的类名、方法名、参数名已经指定&#xff0c;请勿修改&#xff…

【网站项目】“最多跑一次”小程序

&#x1f64a;作者简介&#xff1a;拥有多年开发工作经验&#xff0c;分享技术代码帮助学生学习&#xff0c;独立完成自己的项目或者毕业设计。 代码可以私聊博主获取。&#x1f339;赠送计算机毕业设计600个选题excel文件&#xff0c;帮助大学选题。赠送开题报告模板&#xff…