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

ops/2024/9/19 6:17:10/ 标签: c语言

      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.ppmy.cn/ops/7755.html

相关文章

spring注解驱动系列-- BeanPostProcessor与BeanFactoryPostProcessor

一、BeanPostProcessor与BeanFactoryPostProcessor的定义 一、BeanPostProcessor bean后置处理器&#xff0c;bean创建对象初始化前后进行拦截工作的 二、BeanFactoryPostProcessor beanFactory的后置处理器&#xff0c;在BeanFactory标准初始化之后调用&#xff0c;来定制和…

计算机网络(王道考研)笔记个人整理——第二章

第二章 物理层主要任务&#xff1a;确定与传输媒体有关的一些特性 机械特性&#xff1a;物理连接的特性 规定物理连接时所采用的规格、接口形状、引线数目、引脚数量和排列情况 电气特性 规定传输二进制位时&#xff0c;线路上信号的电压范围、阻抗匹配、传输速率和距离限制等…

【KingSCADA】通过地址引用和弹窗模板实现设备控制

当相同的设备过多时&#xff0c;要做很多相同的弹窗&#xff0c;这种情况下可以通过地址引用和弹窗模板实现设备控制。 1.变量创建 2.画面开发 以阀门控制为例&#xff0c;只需要做一个阀门控制界面模板 3.地址引用 # 4.实现效果

【网络运维知识】—路由器与交换机区别

【网络运维知识】—路由器与交换机区别 一、路由器&#xff08;Router&#xff09;和交换机&#xff08;Switch&#xff09;对比1.1 功能1.2 转发方式1.3 范围1.4 处理方式 &#x1f496;The Begin&#x1f496;点点关注&#xff0c;收藏不迷路&#x1f496; 路由器&#xff08…

面试高频:HTTPS 通信流程

更多大厂面试内容可见 -> http://11come.cn 面试高频&#xff1a;HTTPS 通信流程 HTTPS 的加密流程 接下来说一下 HTTPS 协议是如何进行通信的&#xff1a; HTTPS 通信使用的 对称加密 非对称加密 两者结合的算法 HTTPS 通信时&#xff0c;会先使用 非对称加密 让通信双…

深入理解计算机网络:从基本原理到实践应用

前言&#xff1a; 计算机网络是现代信息技术的基石&#xff0c;它连接了全球数以亿计的设备&#xff0c;使得信息传输和资源共享成为可能。本文将从计算机网络的基本原理出发&#xff0c;深入探讨其关键技术&#xff0c;并分享一些实践应用的经验。 一、计算机网络的基本原理 1…

【Qt】Qt界面构建与对象管理:从 “Hello World“ 到内存释放

文章目录 1. 通过图形化界面创建控件2. 通过纯代码方式创建控件3. 对象树管理与内存管理小结&#xff1a; 在软件开发中&#xff0c;构建用户界面是至关重要的一步。Qt作为一个跨平台的C框架&#xff0c;提供了强大的界面构建工具和对象树管理机制&#xff0c;使得界面开发变得…

李宏毅2022机器学习/深度学习 个人笔记(1)

本系列用于推导、记录该系列视频中本人不熟悉、或认为有价值的知识点 本篇记录第一讲&#xff08;选修&#xff09;&#xff1a;神奇宝贝分类 如图&#xff0c;为了估算某个样本属于某类的概率&#xff0c;在二分类问题中&#xff0c;我们需要计算红框所示的4个参数&#xff0…

Linux Centos 9保姆级系统安装教程

文章目录 下载Centos 9镜像文件安装Centos 下载Centos 9镜像文件 清华大学源网址https://mirrors.tuna.tsinghua.edu.cn/ 安装Centos 所需软件&#xff1a;VMware Workstation 16 Pro 版本里面没有Centos 9&#xff1b; 这里我们选择Centos 7同样可以使用 用户设置

Elasticsearch:使用向量化和 FFI/madvise 加速 Lucene

作者&#xff1a;来自 Elastic Chris Hegarty 在 Lucene 领域&#xff0c;我们一直热切地采用新版本 Java 的功能。这些功能使 Lucene 更接近 JVM 和底层硬件&#xff0c;从而提高了性能和稳定性。这使得 Lucene 保持现代化和具有竞争力。 Lucene 的下一个主要版本&#xff0…

RIME-SVM,基于RIME寒冰优化算法优化SVM支持向量机回归预测 (多输入单输出)-附代码

支持向量机&#xff08;SVM&#xff09; 支持向量机&#xff08;SVM&#xff09;是一种广泛用于分类和回归的强大监督学习算法。在回归任务中&#xff0c;特别是在SVM被用作支持向量回归&#xff08;SVR&#xff09;时&#xff0c;目标是找到一个函数&#xff0c;这个函数在给…

Apache Hadoop 输入格式示例

目录 TextInputFormat 示例 SequenceFileInputFormat 示例 总结 TextInputFormat 示例 描述: TextInputFormat 是 Hadoop 中使用最广泛的输入格式之一&#xff0c;适用于纯文本文件。它将文件按行划分&#xff0c;把每一行的起始偏移量作为键&#xff08;key&#xff09;&am…

JDBC学习

DriverManager&#xff08;驱动管理类&#xff09; Drivermanager的作用有&#xff1a; 1.注册驱动&#xff1b; 2.获取数据库连接 Class.forName("com.mysql.cj.jdbc.Driver"); 这一行的作用就是注册Mysql驱动&#xff08;把我们下载的jar包加载到内存里去&…

实现 Android 设备屏幕录制的批处理脚本

在本文中&#xff0c;我们将介绍如何使用批处理脚本来实现在 Android 设备上进行屏幕录制&#xff0c;并将录制的视频文件传输到计算机上。这个脚本利用了 Windows 的批处理脚本和 Android 的 adb 工具。 背景 在进行 Android 应用开发、教学演示或问题排查时&#xff0c;我们…

毕业设计——基于ESP32的智能家居系统(语音识别、APP控制)

ESP32嵌入式单片机实战项目 一、功能演示二、项目介绍1、功能演示2、外设介绍 三、资料获取 一、功能演示 多种控制方式 ① 语音控制 ②APP控制 ③本地按键控制 ESP32嵌入式单片机实战项目演示 二、项目介绍 1、功能演示 这一个基于esp32c3的智能家居控制系统&#xff0c;能实…

使用51单片机控制T0和T1分别间隔1秒2秒亮灭逻辑

#include <reg51.h>sbit LED1 P1^0; // 设置LED1灯的接口 sbit LED2 P1^1; // 设置LED2灯的接口unsigned int cnt1 0; // 设置LED1灯的定时器溢出次数 unsigned int cnt2 0; // 设置LED2灯的定时器溢出次数// 定时器T0 void Init_Timer0() {TMOD | 0x01;; // 定时器…

三、Flask模型基础

ORM 创建模型 # exts.py&#xff1a;插件管理 # 扩展的第三方插件 # 1.导入第三方插件 from flask_sqlalchemy import SQLAlchemy # ORM插件 from flask_migrate import Migrate # 2. 初始化 db SQLAlchemy() # ORM migrate Migrate() # 数据迁移 # 3. 和app对象绑定 def…

Flink的安装、项目创建、任务打包和部署完整实现,任务实现使用JAVA语言

Flink资源下载地址 Flink安装包下载地址 一、本地模式安装Flink 1、在Linux服务上&#xff0c;创建flink文件夹 mkdir flink 2、上传文件并解压 tar -zxvf flink-1.14.6-bin-scala_2.11.tgz 解压完成后&#xff0c;如图&#xff1a; 3、启动Flink 进入到解压目录下&#x…

Css切换不同窗口

代码 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><title>Title</title></head><style>/*label {*//* display: block;*//*}*/* {padding: 0;margin: 0;}body {height: 100vh;backgroun…

设计模式之原型模式

1、简单介绍 原型模式&#xff08;Prototype Pattern&#xff09;是一种创建型设计模式&#xff0c;它通过复制现有的实例来创建新对象&#xff0c;而不是通过调用类的构造函数来创建新实例。这种模式适用于需要快速复制大量相同或相似对象&#xff0c;或者创建对象需要消耗大量…