第八次前端作业,要求结合div和css来做一个小页面,这个工程有许多小细节,特别是在css中,本次采用内部样式表

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            list-style: none;
            
        }
        .all{
            margin: 10px;
            padding: 10px;
        }
        .pic{
            border: 2px solid goldenrod;
            height: 230px;
            width: 1200px;
            
        }
        .pic li{
            float: left;
            margin: 10px;
            margin-top: 20px;
            /* margin-top是来限定pic下的li的上边距 */
        }
        .pic li p{
            text-align: center;
        }
        /* .t1{
            border: 1px solid goldenrod;
            height: 20px;
            width: 500px;
            position: relative;
            
            
        }
        .ti li{
            float: left;
            margin: 1px;
        } */
        .a1{
            
            width: 590px;
            height: 250px;
            border: 2px solid goldenrod;
            /* 设置边框的粗细 */
            float: left;
            /* 设置这里的div是为了可以多个div并排 */
            margin-bottom: 20px;
        }
        .a1 div{
            float: left;
            /* 如果不设置float,那么文字就会飘在父级div下方 */
        }
        .a2{
            width: 250px;
            height: 280px;
            border: 2px solid goldenrod;
            float: left;
        }
        .a2 div{
            margin-top: 30px;
            margin-left: 15px;
            line-height: 16px;
        }
        .a3{
            width: 930px;
            height: 280px;
            border: 2px solid goldenrod;
            float: left;
            margin-left: 50px;
        }
        .a3 div{
            margin-left: 15px;
            margin-right: 15px;
            line-height: 26px;
            /* 设置行高,间接设置行间距 */
        }
    </style>
</head>
<body>
    <div class="all">
        <div>
            <ul class="pic">
                <li>
                    <img src="images/i01.jpg" width="150px">
                    <p>天街</p>
                </li>
                <li>
                    <img src="images/i02.gif" width="216px">
                    <p>中天门</p>
                </li>
                <li>
                    <img src="images/i03.jpg" width="212px">
                    <p>旭日东升</p>
                </li>
                <li>
                    <img src="images/i04.jpg" width="242px">
                    <p>五岳独尊</p>
                </li>
                <li>
                    <img src="images/i05.jpg" width="225px">
                    <p>云海玉盘</p>
                </li>
            </ul>
        </div>
        <br>
        <div class="a1">
            <p style="position: absolute;margin-left:70px;color:black;">泰山摄影</p>
                <img src="images/bg01.gif" width="590px">
                <!-- 这里文字内嵌在图片上方,先把文字放在图片前,再加position,设置absolute,注意设置左边距 -->
            <div>
                <img src="images/caishixi.jpg" style="margin-top: 20px;margin-left:20px">
                <p align="center">彩石溪</p>
            </div>
            <div style="float: left;width:380px;margin-left:10px">
                    进入桃花峪,行约2公里,溪中流水之下忽如才是铺就,溪底一条条石纹五彩纷呈,
                    阳光照耀下,分外生动,这就是著名的“彩石溪”。完完全全的溪水就像是被彩石染上了颜色,
                    也像是一条五彩的飘带,在此流淌得格外精神。动人的彩石时长引得有人驻足,如果你细心,
                    就可看见水中的赤鳞鱼。
            </div>
            
        </div>
        <div class="a1" style="margin-left: 50px;">
            <p style="position: absolute;margin-left:70px;color:black;">景点推荐</p>
            <img src="images/bg02.gif" width="590px">
            <div>
                <img src="images/shanziya.jpg"  style="margin-left:10px;margin-top:20px;">
                <p align="center" style="margin-top: 5px;">扇子崖</p>
            </div>
            <div style="float:left;width:370px;margin-left:10px;">
                位于泰山西溪西侧的扇子崖,奇峰突兀,高耸峻峭,形如扇面,故名。
				崖上有明人杨博题刻摩崖石刻“仙人掌”。崖西有铁梯,攀援可登崖巅,
				北眺龙角山,九女寨历历在目,西望傲徕峰尽收眼底。向东俯视,
				龙潭水库宛若镶嵌在西溪的一颗璀璨的明珠,闪闪发光。清人孙宝僮有诗云:
				“剑峰怒刺天,积铁拔千仞;俯临鬼谷幽,旁倚丈人峻”,的确写出了扇子崖的风韵。
            </div>
        </div>
        <br>
        <br>
        <div class="a2">
            <img src="images/bg03.gif" width="250px" height="30px" style="position: absolute;z-index: 1;">
            <!-- 图片内嵌图片,除了设置position,还要设置z-index,数字越大,越靠近上方 -->
            <img src="images/arrow.gif" style="position:absolute;margin-left:10px;z-index:2">
            <p style="position:absolute;float: left;margin-left:60px;margin-top:5px;color:black;z-index:3">泰山旅游景点</p>
            <div style="margin-top: 40px;font-size:14px;">
                <p>岱庙:宋天贶殿 ……</p>
				<p>丽区:王母池  ……</p>
				<p>幽区:岱宗坊  ……</p>
				<p>妙区:南天门  ……</p>
				<p>奥区:后石坞 ……</p>
				<p>旷区:扇子崖  ……</p>
				<p>秀区:桃花峪 ……</p>
				<p>奇观:旭日东升 ……</p>
            </div>
        </div>
        <div class="a3">
            <p style="position:absolute;margin-left: 70px;margin-top:5px;color:black;font-weight:bolder;">泰山介绍</p>
            <img src="images/bg05.gif" width="930px" height="30px">
            <div style="margin-top: 5px;">
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;泰山突兀而立于华北大平原东侧的齐鲁古国,东临浩波无涯的大海,西靠源远流长、奔流到海不复回的黄河,南有汶、泗、淮之水。纵览东部沿海广大区域,泰山踞高临下、凌驾于齐鲁丘群之上,真正成了茫茫原野上的"东天一柱"。这样,古人们便有了泰山为天下之中心的感觉。<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;泰山除了深厚的文化内涵,还具有丰富的自然美,如果我们把风景自然美的形象特征概括为雄、奇、险、秀、幽、奥、旷的话,那么泰山除了从总体上和宏观上具有雄伟的特征外,还在雄中蕴含着奇、险、秀、幽、奥、旷等美的形象。<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;泰山风景区内,有山峰156座,崖岭138座,名洞72处,奇石72块,溪谷130条, 瀑潭64处,名泉72眼,古树名木万余株,寺庙58座,古遗址128处,碑碣1239块,摩崖刻石1277处。主要分布在岱阳、岱顶、岱阴及灵岩。<br>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;泰山是一座天然的历史、艺术博物馆,仅在泰山的中轴线上就现存有各种石刻1800余处,有的为帝王亲制,有的出自名流之手,大都文辞优美,书体高雅,制作精巧…… </div>
            </div>

        </div>
        <br><br>
    </div>
</body>
</html>

最后的效果

Read more »

上个月在复习链表知识时,本来想动手运用下,但是我没想到我上一篇关于链表的文章写的程序漏洞百出,加上其他班要求写一个基于单链表的图书管理系统,我的班没有布置,并且大二要学数据结构,又听说链表是数据结构里最简单的一部分,只得花了一个月来查阅各种资料、阅读各种博文,在综合网友们的代码后,自己整理了下,写了这个图书管理系统(一定还有bug我没发现),代码如下:

#include<iostream>
#include<cstring>
#include<conio.h>
#include<cstdlib>
#include<algorithm>
#include<iomanip>
#include<Windows.h>
using namespace std;

struct mInfo {
	unsigned long long ID;
	char name[21];
	int score;
};

struct mList {
	struct mInfo data;
	struct mList* next;
};

mList* mCreate(mList* mHead)
{
	//initialize the list
	mHead = (mList*)malloc(sizeof(mList));
	if (mHead == NULL) {
		return 0;
	}
	mHead->next = NULL;
	return mHead;
}

mList* add_m(mList* mHead)
{
	mList* s, * p;//p->pointer to next,s->pointer to data
	p = mHead;
	int num = 0;
	cout << "How many memberships do you want to registry: ";
	cin >> num;
	for (int i = 0; i < num; i++) {
		s = (mList*)malloc(sizeof(mList));
		cout << "memership No." << i+1 << " 's info" << endl;
		cout << "enter the num: ";
		cin >> s->data.ID;
		cout << "enter the name: ";
		cin >> s->data.name;
		cout << "enter the score: ";
		cin >> s->data.score;
		p->next = s;
		p = s;
		system("cls");
	}
	p->next = NULL;
	return mHead;
}

void print_m(mList* L)
{
	cout << "num" << '\t' << "name" << '\t' << "score\n";
	mList* p;
	p = L->next;
	while (p != NULL) {
		cout.setf(ios::fixed);
		cout << p->data.ID << '\t' << p->data.name << "\t" << p->data.score << endl;
		p = p->next;
		//system("pause");
	}
}

void insert_m(mList* L)
{
	mList* p, * s;//p->pointer to next,s->pointer to data
	p = L->next;
	s = (mList*)malloc(sizeof(mList));
	while (p->next != NULL) {
		p = p->next;
	}
	cout << "enter the ID for membership: ";
	cin >> s->data.ID;
	cout << "enter the name: ";
	cin >> s->data.name;
	cout << "enter the score: ";
	cin >> s->data.score;
	s->next = p->next;
	p->next = s;
}

void del_m(mList* L)
{
	mList* p, *pre;
	p = L->next;
	pre = p;
	unsigned long long num = 0;
	cout << "enter the ID: ";
	cin >> num;
	while (p != NULL) {
		if (p->data.ID == num) {
			pre->next = p->next;
			free(p);
			cout << "delete successfully\n";
			return;
		}
		pre = p;
		p = p->next;
	}
	cout << "could not find the book that you want to delete\n";
}

void edit_m(mList* L) 
{
	mList* p;
	unsigned num = 0;
	p = L->next;
	cout << "enter the num of the book that you want to delete: ";
	cin >> num;
	while (p != NULL) {
		if (p->data.ID == num) {
			cout << "you can only edit the name\n";
			/*cout << "enter the new num: ";
			cin >> p->data.ID;*/
			cout << "enter the new name: ";
			cin >> p->data.name;
			//cout << "enter the new score: "
			return;
		}
		p = p->next;
	}
	cout << "could not find the book that you want to edit\n";
	p = p->next;
}

void search_m(mList* L)
{
	mList* p;
	unsigned long long num = 0;
	p = L->next;
	cout << "enter the book that you want to search: ";
	cin >> num;
	while (p != NULL) {
		if (p->data.ID == num) {
			cout << "num" << '\t' << "name" << '\t' << "price\n";
			cout << p->data.ID << '\t' << p->data.name << '\t' << p->data.score << endl;
			//system("pause");
			return;
		}
		p = p->next;
	}
	cout << "not found\n";
	system("pause");
}

struct info_b {
	unsigned long long ID;
	char name[21];
	double price;
};

struct bList {
	struct info_b data;
	struct bList* next;
};

struct bList* bCreate(bList* bHead)
{
	//initialize the list
	bHead = (struct bList*)malloc(sizeof(struct bList));
	if (bHead == NULL) {
		return 0;
	}
	bHead->next = NULL;
	return bHead;
}

bList* add_b(bList* bHead)
{
	bList* p = NULL, * s = NULL;
	int num = 0;
	p = bHead;
	cout << "How many books that you want to registry: ";
	cin >> num;
	for (int i = 0; i < num; i++) {
		cout << "book No." << i + 1 << " 's info\n";
		s = (bList*)malloc(sizeof(bList));
		cout << "enter the book ID: ";
		cin >> s->data.ID;
		cout << "enter the book name: ";
		cin >> s->data.name;
		cout << "enter the book price: ";
		cin >> s->data.price;
		p->next = s;
		p = s;
		system("cls");
	}
	p->next = NULL;
	return bHead;
}

void print_b(bList* L)
{
	bList* p;
	p = L->next;
	cout << "book num" << '\t' << "book name" << '\t' << "book price\n";
	while (p != NULL) {
		cout.setf(ios::fixed);
		cout << p->data.ID << '\t' << p->data.name << '\t' << setprecision(2) << p->data.price << endl;;
		p = p->next;
	}
}

void insert_b(bList* L)
{
	bList* p, * s;
	p = L->next;
	while (p->next != NULL) {
		p = p->next;
	}
	s = (bList*)malloc(sizeof(bList));
	cout << "enter the book ID: ";
	cin >> s->data.ID;
	cout << "enter the book name: ";
	cin >> s->data.name;
	cout << "enter the book price: ";
	cin >> s->data.price;
	s->next = p->next;
	p->next = s;//pointer point to the next data
}

void del_b(bList* L)
{
	bList* p,* pre;
	unsigned long long num = 0;
	p = L->next;
	pre = p;
	cout << "enter the book ID that you want to delete: ";
	cin >> num;
	while (p != NULL) {
		if (p->data.ID == num) {
			pre->next = p->next;
			free(p);
			cout << "delete successfully\n";
			return;
		}
		pre = p;
		p = p->next;
	}
}

void edit_b(bList* L)
{
	bList* p;
	p = L->next;
	unsigned long long num = 0;
	cout << "enter the book ID that you want to edit: ";
	cin >> num;
	while (p != NULL) {
		if (p->data.ID == num) {
			cout << "enter the book ID: ";
			cin >> p->data.ID;
			cout << "enter the book name: ";
			cin >> p->data.name;
			cout << "enter the book price: ";
			cin >> p->data.price;
			cout << "edit successfully\n";
			return;
		}
		p = p->next;
	}
}

void search_b(bList* L)
{
	bList* p;
	p = L->next;
	unsigned long long num;
	cout << "enter the book ID that you want to search: ";
	cin >> num;
	while (p != NULL) {
		if (p->data.ID == num) {
			cout.setf(ios::fixed);
			cout << "book ID" << '\t' << "book name" << '\t' << "book price\n";
			cout << p->data.ID << '\t' << p->data.name << '\t' <<setprecision(2) << p->data.price << endl;
			return;
		}
		p = p->next;
	}
	cout << "opps, could not find the book\n";
}

void total_b(bList* L)
{
	double sum = 0;
	bList* p = L->next;
	while (p != NULL) {
		sum += p->data.price;
		p = p->next;
	}
	cout << "calculating...\n";
	Sleep(1500);
	cout.setf(ios::fixed);
	cout << "the total cost: " << setprecision(2) << sum << '$' << endl;
}

void login()
{

	string account, password;
	int index = 0;
	char ch;
	while (1) {
		cout << "account: ";
		cin >> account;
		cout << "password: ";
		while ((ch = _getch()) != '\r') {
			if (ch == 8) {
				password[index] = '\0';
				break;
			}
			password += ch;
			index++;
			if (ch != '\b') {
				cout << "*";
			}
			else {
				if (index != 0) {
					cout << '\b' << " " << '\b';
					index--;
				}
			}
		}
		if ((account == "admin") && (password == "123456")) {
			break;
		}
		else {
			cout << "\nerror,check your account or password" << endl;
			system("pause");
			fflush(stdin);
			password.clear();
			system("cls");
		}
	}
}

int menu()
{
	int mode = 0;
	cout << "**********************************************" << "\n" << endl;
	cout << "* book sales management system(admin edition)" << '\n' << endl;
	cout << "*     1.membership management  " << '\n' << endl;
	cout << "*     2.books management       " << '\n' << endl;
	cout << "*     3.clear the bill         " << '\n' << endl;
	cout << "*     0.sign out               " << '\n' << endl;
	cout << "**********************************************" << "\n" << endl;
	cout << "choose a mode: ";
	cin >> mode;
	return mode;
}

int main()
{
	login();
	mList* mHead = NULL, * M = NULL;
	bList* bHead = NULL, * B = NULL;
	int mode = 0;
	system("cls");
	while (1) {
		mode = menu();
		if (mode == 1) {
			while (1) {
				system("cls");
				int mode1;
				cout << "book sales management system > membership management " << endl;
				cout << "******************************" << "\n" << endl;
				cout << "* 1.initialize the system" << '\n' << endl;
				cout << "* 2.show all the memberships " << '\n' << endl;
				cout << "* 3.add membership           " << '\n' << endl;
				cout << "* 4.edit membership          " << '\n' << endl;
				cout << "* 5.delete membership        " << '\n' << endl;
				cout << "* 6.search the membership    " << '\n' << endl;
				cout << "* 0.back to main menu        " << '\n' << endl;
				cout << "******************************" << '\n' << endl;
				cout << "select a mode: ";
				cin >> mode1;
				if (mode1 == 1) {
					mHead = mCreate(mHead);
					M = add_m(mHead);
					system("pause");
				}
				else if (mode1 == 2) {
					print_m(M);
					system("pause");
				}
				else if (mode1 == 3) {
					insert_m(M);
					system("pause");
				}
				else if (mode1 == 4) {
					edit_m(M);
					system("pause");
				}
				else if (mode1 == 5) {
					del_m(M);
					system("pause");
				}
				else if (mode1 == 6) {
					search_m(M);
					system("pause");
				}
				else if (mode1 == 0) {
					system("pause");
					system("cls");
					break;
				}
				else {
					cout << "opps, please check what you inputted\n";
					system("pause");
					system("cls");
				}
			}
		}
		else if (mode == 2) {
			while (1) {
				system("cls");
				cout << "book sales management system > book management" << endl;
				cout << "***************************" << '\n' << endl;
				cout << "* 1.initialize the system" << '\n' << endl;
				cout << "* 2.browse the book   " << "\n" << endl;
				cout << "* 3.add book          " << '\n' << endl;
				cout << "* 4.edit book         " << '\n' << endl;
				cout << "* 5.delete book       " << '\n' << endl;
				cout << "* 6.search the book   " << '\n' << endl;
				cout << "* 0.back to main menu " << '\n' << endl;
				cout << "***************************" << '\n' << endl;
				int mode2;
				cout << "select one mode: ";
				cin >> mode2;
				if (mode2 == 1) {
					bHead = bCreate(bHead);
					B = add_b(bHead);
					system("pause");
				}
				else if(mode2 == 2) {
					print_b(B);
					system("pause");
				}
				else if(mode2 == 3) {
					insert_b(B);
					system("pause");
				}
				else if (mode2 == 4) {
					edit_b(B);
					system("pause");
				}
				else if (mode2 == 5) {
					del_b(B);
					system("pause");
				}
				else if (mode2 == 6) {
					search_b(B);
					system("pause");
				}
				else if (mode2 == 0) {
					system("pause");
					system("cls");
					break;
				}
				else {
					cout << "opps, please check what you inputted\n";
					system("pause");
					system("cls");
				}
			}
		}
		else if (mode == 3) {
			double sum = 0,temp = 0;
			while (1) {
				cout << "Do you want to clear the bill?(y/n) ";
				char ch;
				cin >> ch;
				if ((ch == 'y') || (ch == 'Y')) {
					total_b(B);
					//system("pause");
				}
				else if ((ch == 'n') || (ch == 'N')) {
					cout << "exiting...\n";
					Sleep(2000);
					//system("pause");
					break;
				}
				system("pause");
				system("cls");
				break;
			}
		}
		else if (mode == 0) {
			system("pause");
			system("cls");
			break;
		}
		else {
			cout << "opps, please check what you inputted\n";
			system("pause");
			system("cls");
		}
	}
}

如果各位读者能发现我的代码中的bug的话,欢迎指出,也可和我私信一同讨论!

Read more »

这是某次作业的代码,要求创建一个点类,因为不听课,在打代码的过程中遇到许多坑,现在来总结以填坑

#include<iostream>
#include<cmath>
using namespace std;
class Point{
private:
    float x, y;
public:
    Point();//不带参的构造函数
    Point(float xx, float yy);//带参的构造函数
    void set();
    void show();
    Point calc(Point p);
    float getX();
    float getY();
    //这两个函数是得到point类私有数据的关键函数,外部不可以直接访问类的私有数据,需要通过些特殊手段
};

Point::Point()
{
    x = 0;
    y = 0;
}

Point::Point(float xx,float yy)
{
    x = xx;
    y = yy;
}

void Point::set()
{
    cout << "enter the x and y: ";
    cin >> x >> y;
}

void Point::show()
{
    cout << "x = " << x << endl;
    cout << "y = " << y << endl;
}

Point Point::calc(Point p)
{
    Point temp;
    temp.x = (x - p.x) * (x - p.x);
    temp.y = (y - p.y) * (y - p.y);
//类内部函数可以直接使用p.x和p.y来调用数据
    return temp;
}

float Point::getX()
{
    return x;
}

float Point::getY()
{
    return y;
}

float calc_dis(Point p)
{
    float x, y, dis;
    x = p.getX();
    y = p.getY();
//非类内部函数直接用p.x+p.y会报错    
    dis = sqrt(x + y);
    return dis;
}

int main()
{
    Point p2, p3;
    float dis;
    // p1.set();
    Point p1(4, 5);
    Point p4;
    p2.set();
    //p1.show();
    // p2.show();
    p3 = p2.calc(p1);
    dis = calc_dis(p3);
    cout << "distance = " << dis << endl;
    p4.show();
}
Read more »

这两周的c++课都没怎么听,也许是对自己太自信了,第一次的类的作业竟然不会做(丢人),翻看了书本,加上论坛大佬的代码才大概弄明白;然而这次的上机作业,要求再用类写个链表系统,做的时候有发现问题了,虽然之前总结过链表,但是是用结构体写的,貌似不支持string(基于类的链表支持string),这次又浏览了论坛上大佬的帖子,总结了一波,做出了以下单链表系统(阉割版)

#include<iostream>
#include<string>
using namespace std;

typedef struct student {
    string name, ID, publisher, author;
    student* next;
} student, * stu;

class list {
public:
    ~list();//析构函数
    list(string, string, string, string);//构造函数
    void search(string name);
    void insert(string, string, string, string);
    void del(string);
    void print();
    void edit(string);
    struct student* head;
};

list::~list()
{
    cout << "release successfully" << endl;
    system("pause");
}
//析构函数不要出现在主函数里,不然会报错

list::list(string a, string b, string c, string d)
{
    head = new student;
    head->next = NULL;
    student* s = NULL;
    s = new student;
    s->name = a;
    s->ID = b;
    s->author = c;
    s->publisher = d;
    s->next = head->next;
    head->next = s;
}
//初始化链表

void list::search(string name)
{
    student* p = head->next;
    while (p != NULL) {
        if (p->name == name) {
            //return p;
            cout << "name: " << p->name << endl;
            cout << "ID: " << p->ID << endl;
            cout << "author: " << p->author << endl;
            cout << "publisher: " << p->publisher << endl;
            break;
        }
        p = p->next;
    }
    system("pause");
    //return NULL;
}
//查找链表中的成员

void list::insert(string a, string b, string c, string d)
{
    student* p = head, * s = NULL;
    s = new student;
    s->name = a;
    s->ID = b;
    s->author = c;
    s->publisher = d;
    s->next = p->next;
    head->next = s;
}
//往链表添加新成员

void list::del(string name)
{
    student* p = head->next, * s = head, * q = NULL;
    q = new student;
    while (p != NULL && p->name != name) {
        p = p->next;
        s = s->next;
    }
    if (p->name == name) {
        s->next = p->next;
        q = p;
        delete q;
        cout << "delete successfully" << endl;
    }
}
//删除链表的结点

void list::print()
{
    student* p = head->next;
    cout << "name\t" << "ID\t" << "author\t" << "publisher" << endl;
    while (p != NULL) {
        cout << p->name << '\t' << p->ID << '\t' << p->author << '\t' << p->publisher << endl;
        p = p->next;
    }
    cout << endl;
}
//打印链表

void list::edit(string name)
{
    student* p = head->next;
    while (p != NULL) {
        if (p->name == name) {
            break;
        }
        p = p->next;
    }
    while (1) {
        cout << "what data do you wanna edit(enter 'none' to exit): ";
        string temp;
        cin >> temp;
        cout << "enter the new data: ";
        if (temp == name) {
            cin >> p->name;
        }
        else if (temp == "ID") {
            cin >> p->ID;
        }
        else if (temp == "author") {
            cin >> p->author;
        }
        else if (temp == "publisher") {
            cin >> p->publisher;
        }
        else if (temp == "none") {
            break;
        }
        else {
            cout << "error, please check what you enter" << endl;
        }

    }
}
//编辑链表成员的数据

int main()
{
    list li("a", "b", "c", "d");
    while (1) {
        cout << "---------------------------\n";
        cout << "1.add the info             \n";
        cout << "2.search the info          \n";
        cout << "3.edit the info            \n";
        cout << "4.delete the info          \n";
        cout << "5.print the list           \n";
        cout << "0.exit                     \n";
        cout << "---------------------------\n";
        cout << "choose a mode: ";
        int mode;
        cin >> mode;
        if (mode == 1) {
            string a, b, c, d;
            cout << "enter the new data(name ID author publisher): ";
            cin >> a >> b >> c >> d;
            li.insert(a, b, c, d);
        }
        else if (mode == 2) {
            string temp;
            cout << "enter the book's name that you want to search: ";
            cin >> temp;
            li.search(temp);
        }
        else if (mode == 3) {
            string temp;
            cin >> temp;
            li.edit(temp);
        }
        else if (mode == 4) {
            string temp;
            cin >> temp;
            li.del(temp);
            system("pause");
        }
        else if (mode == 5) {
            li.print();
            system("pause");
        }
        else if (mode == 0) {
            cout << endl;
            system("pause");
            break;
        }
        else {
            cout << "error, please select the mode again\n";
            system("pause");
        }
        system("cls");
    }
}
Read more »

过去这几天一直颓废,断断续续写下这几天的感受。

从颓废中走出

2.8-2.15 颓废的一周,一天醒着的16小时,有8小时是泡在B站的,加上自己本身是军迷,对一些战争类的电影比较感兴趣,点开推荐的一个视频后,便一发不可收拾。B站的网课,看不够三个番茄钟,马上就去首页看推荐的视频,唯独在洛谷做题时还能保持一个比较专注的状态。然后过年那几天,学习的时间不超过两小时,有人说,过年了,看自己去年高考备考那么累,玩几天没问题的。当时我也是这么想的,可我没想到人的惰性会这么强大,一连续玩了三天,想着初四要开工了,继续学习,我七点起床,坐在书桌前,打开电脑,打上B站的网址,手不自主的点开了战争电影的推荐,又开始颓废的上午……中午睡醒后,我又打开了B站,推荐里出现了老番茄的毕业vlog,这个视频在我的收藏夹里,我点开了它,当看到老番茄平均绩点3.96那里,我不禁陷入了沉思,难道我注定要这样颓废下去?这时候,我的微信会话框出现了一个小红点,原来是浩宇师兄,他在给学弟学妹们分享干货,此刻,我正在回忆20天前的我,站在华附教室的讲台上自信的样子,我又陷入了沉思,难道我……"该醒醒了",我的目光洒在我的右手手环上,"I PROMISE",戴着它我却没有做到……

找回状态

2.16 今天的学习节奏稍微换了下,以往都是看着网课来敲代码,今天直接刷一整天的洛谷,反倒发现这样的方式我更能沉浸在里面,有效避免了学习中途去看片的颓废行为,事后想了下,这不就是我高三那段时间的状态嘛,不断地刷题,to be continue……

访问故地

2.17 事实证明,我果然是不适合长时间更着网课学,还是要动手才不会那么容易分心。 今天下午闲着没事 其实是敲代码敲累了,回访故居,我在那个区域居住了四年,后来搬走了,去年大学开学前又搬回了那附近,十年前,一片落后的景象,河涌污泥遍布,成群的烂尾楼……十年后重返故地,一片繁华的景象。这一切对我来说,既熟悉又陌生,曾经的烂尾楼早已被推倒,取而代之的是林立的高楼。走进那一个个小巷,感受那富含历史积淀的民风;生了锈的路牌,见证着这块区域的变迁;而我,也在这变迁之中,不断刷新着我对这个世界的认知。

"童年的纸飞机,现在终于飞回我手里",耳机里突然出现这一段歌词,此时我骑着单车,沿着绿化后的河流,心中满是感慨

写到这里,我的状态逐渐回暖,我也不再去过多理会内卷,内卷往往被当今的媒体过分渲染,春节前看着部门的好友做出了一个UI设计很好看的小游戏,心中满是蕉绿,过一会缓过来,蕉绿顶个p用,不必过多关注他人,每一天在自己的节奏里不断多学一点就是进步。

多出去走走

Read more »

1.17

最近在考试,好久没更了,就断断续续写下自己这些天的所思所想吧。

1.19

刚考完试,这几周的压力、负面情绪都挤压了在一起,对职业生涯的焦虑,学自己这学期忙碌而又不是很充实的遗憾、失落,总体给人一个很丧的感觉,但是又不想把自己的负面情绪散播出去,影响到在意我的好友们,过去,我常常在以他人的目光,有时他人的一句话甚至会作为我的情绪的晴雨表,不得不说我以前实在是太玻璃心了。这学期我一直在想,我发朋友圈的目的是为了什么,是为了获得他人的认可吗?是要他人来评价自己吗?这学期来,我尝试过发过几条朋友圈,都是获得比较少赞的,当时我还是比较失落的。在某一个夜晚,我躺在床上翻来覆去睡不着,忽然想到这个问题,相比起高中,我在大学发圈的频率大大上升,在成为班长之后,我结识了更多的人,有时的朋友圈可以有80+的赞,有时也寥寥无几。这时我突然回忆起我高考完和Sam的一次通话,"其实吧,我发朋友圈是为了记录生活,不管别人赞不赞,开心的是自己",想到这里,突然豁然开朗。

1.20

其实我知道自己一直有轻微的抑郁,心理方面有时会表现得很病态,一直找不到一种解脱的方式,自己写博客,就当是一种泄愤的方式,一种自我治疗吧。我的个人兴趣爱好和很多人表现得不一样,特别是行为方式上,有一些人格格不入,我们相互不能理解对方。有时我打开音乐播放器,点击纯音乐,查看评论,发现原来这个世界上还是有那么一群人和我有着相同的感受,无言却胜千言,不同人有着不同的经历,在外人看来,你可能就是矫情,可他没经历过,那就让他说去吧。

1.21 今早很早就醒了,大概六点,继续沿着昨天的思绪,回忆整个高三越来越发现我和Sam太像了,相似的经历,相近的行为作风、性格,真的很高兴能在高三与你做朋友、共同进步,在学习和生活上,我们相互较劲,有不好的情绪,我们相互倾诉。

其实高三我还想感谢潘,你的出现,让我感到了前所未有的压力,当然是在认识她之后。整个高三,我都是以你为目标,不断想超越你,在球场上,有一半时间都是我去防你,一想到她,我就防的更积极,也有很多时候我主攻你。尽管我高三这样做在外人看起来真的好变态,高考完那个晚上,我也这样认为[facepalm],我高考完回到教室,对你说的那一声谢谢,让我的高三得到了解脱,尽管我们以后可能不会再有交集,但还是真的很感谢你!

1.22 今日大学城寒招队伍碰面,新认识了许多有趣的小伙伴,个个都是人才,说话又好听(滑稽)。吹完水后,又与Sam相约大学城,把整个华师校区都骑了一遍,才发觉,这才是我高考前梦中隐约出现大学该有的样子(这里没有黑南海),有人曾和我说过,有机会要去别的大学,甚至是本学校的其他校区看看,对比了石牌,大学城和华工五山,果然越好的大学,对于校园环境、设施的建设总是做的比较好的,这就不难解释为什么中国营造着拼了命要考上好大学的氛围。图书馆,教学楼,各学院院楼,阳光映射在人工湖上,在轻微的波澜中,透过竹林,鱼鳞般阳光的碎隙格外显眼……

1.23

Read more »

//二分查找判断某个元素是否在序列里
long search(int a[],int low,int high,int k){
    if(low <= high){
        int mid = low + (high - low) / 2;
        if(k == a[mid]){
            return 1;//找到了返回1
        }else if(a[mid] > k){
//比中值小在左边找            
            return search(a, low, mid - 1, k);
        }else{
//比中值大在右边找            
            return search(a, mid + 1, high, k);
        }
    }
    return 0;
//如果都找不到默认返回0    
}
//oj的题目是给定长度为n的不下降序列,做m个询问
//1.从左逼近(直接丢函数包)
long fun(long a[],long low,long high,long key)
{
    int mid = low + (low + high) / 2;
    if(low <= high){
        if(a[mid] < key){
//在右边查找            
            return fun(a, mid + 1, high, key);
        }
        if(a[mid] > key){
//在左边查找            
            return fun(a, low, mid - 1, key);
        }
        else{
/*如果找到目标元素,判断有无重复,有的话取最大下标*/
            while(mid>=0){
                if(a[mid]!=key){
                    break;
                }
                mid++;
            }
        }
    }
    return mid;
}
//二分查找(从右逼近)
long fun(int a[],int target ,int temp)
{
    int low = 0, high = target, int temp, mid;
    while(low < high){
        mid = (low + high) / 2;
        if(a[mid] == taret){
            high = mid;
        }
        else if(a[mid] > target){
            high = mid;
        }else{
            low = mid + 1;
        }
    }
    if(a[temp] < target){
        return temp + 2;
    }
    /*这里是来区分有没有找到目标值,只要从始至终都没有找到目标
    元素,返回n+2*/
    return low + 1;
}
/*计算包含再给定区间里的序列数值的个数*/
#include<iostream>
#include<cstdlib>
#include<algorithm>
using namespace std;
//这里输入的序列是不按照顺序的
int left(int a[], int target, int temp) {
	int low = 0, high = temp;
	int mid;
//左端不断向右边逼近    
	while (low < high) {
		mid = (low + high) / 2;
		if (a[mid] == target) {
			low = mid + 1;
		}else if (a[mid] < target) {
			low = mid + 1;
		}
		else if (a[mid] > target) {
			high = mid;
		}
	}
	return low;
}
int right(int a[], int target, int temp) {
	int low = 0, high = temp;
	int mid;
//右端不断向左端逼近    
	while (low < high) {
		mid = (low + high) / 2;
		if (a[mid] == target) {
			high = mid;
		}
		else if (a[mid] > target) {
			high = mid;
		}
		else if (a[mid] < target) {
			low = mid + 1;
		}
	}
	return low;
}

int main()
{
	int i, j, k, n, m, p, q;
	cin >> n >> m;
//n表示有几个数字,m表示要输入几组数字
	int* a = (int*)malloc(n * sizeof(int));
	for (i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	for (j = 0; j < m; j++) {
		cin >> p >> q;//p<=q,p是左区间,q是右区间
		cout << left(a, q, n) - right(a, p, n) << endl;
/*left把n不断往左靠,使得右边界逼近q,right把p不断右移,
不断逼近右边界*/
	}
	free(a);
}
/*排完序后再放进函数里,left的作用:
对比左数和序列里的每一个数,返回小于p的数的序号
right是让q与序列的数比较,返回大于q的序号
然后大减小就得到了区间里包含的数*/
Read more »

花了两周整理链表的相关知识

以一个主函数和多个函数的形式来呈现

/*链表合集*/
#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct node{
    int a;
    struct node *next;
} Node;
//排序
void Sort(Node*head){
    node *p, *s, *pt;
    p = head;
    s = p->next;
    while (p->next != NULL){
        while(s->next != NULL){
            if(p->next > s->next){
                pt->next = p->next;
                p->next = s->next;
                s->next = pt->next;
            }
            s = s->next;
        }
        p = p->next;
        pt = s;
    }
}

Node *add(Node*head,int num){//在表尾插入元素
    Node *p = NULL, *pr = head;
    p = (Node *)malloc(sizeof(Node));
    if(p == NULL){
        cout << "no enough memory to allocate";
    }
    if(head == NULL){
        head = p;
    }else{
        while(pr->next != NULL){
            pr = pr->next;
        }
        pr->next = p;
    }
    p->a = num;
    p->next = NULL;
    return head;
}
//打印链表
void show(Node*head){
    Node *p = head;
    while(p != NULL){
        cout << p->a << " ";
        p = p->next;
    }
}

void del(Node*head){//释放申请的内存空间
    Node *p = head, *pr = NULL;
    while(p != NULL){
        pr = p;
        p = p->next;
        free(pr);
    }
}
//删除链表里某一个节点
Node* Delete(Node*head,int num){
    Node *p = head, *pr = head;
    //pr是目标元素前一个节点
    if(head == NULL){
        cout << "empty table";
        return head;//空表退出
    }
    while(num != p->a && p->next != NULL){
        //未找到且不是空表
        pr = p;
        p = p->next;//p直接指向当前节点的下一节点
    }
    if(num == p->a){//找到了待删除节点
        if(p == head){
            head = p->next;//直接让头指针指向待删除结点p的下一节点
        }else{
            pr->next = p->next;
            //前一节点的指针域指向待删除结点的下一节点
        }
        free(p);
    }else{//到表尾且没找到
        cout << "not found";
    }
    return head;
}
//在链表里插入元素
Node* insert(Node*head,int num){
    Node *pr = head, *p = head, *temp = NULL;
    p = (Node *)malloc(sizeof(Node));
    if(p == NULL){
        cout << "no enough memory";
        exit(0);
    }
    p->next = NULL;//待插入节点指针域为空指针
    p->a = num;//待插入节点的数值域为num
    if(head == NULL){
        head = p;//若原链表为空表,待插入节点为头节点
    }else{//若为非空
    //若未找到待插入节点的位置且未找到表尾则继续找
        while(pr->a < num && pr->next != NULL){
            temp = pr;//temp保存当前节点的下一节点
            pr = pr->next;//pr指向当前节点的下一节点
        }
        if(pr->a >= num){
            if(pr == head){//若在头节点前插入新节点
                p->next = head;
            //将新节点的指针域指向原链表的头节点
                head = p;//让head指向新节点
            }else{//在链表中部插入新节点
            //进行排序
                pr = temp;
                p->next = pr->next;
                pr->next = p;
            }
        }else{//若在表尾插入新节点
            pr->next = p;//让末节点的指针域指向新节点
        }
    }
    return head;//返回插入新节点猴的链表头指针head的值
}

int main()
{
    int num;
    char ch;
    struct node *head = NULL;
    do{
        cin >> num;
        if(num >= 0){
            head = add(head, num);
            show(head);
        }
        if(num % 5 ==0){
            cout << "continue?(y/n)";
            cin >> ch;
            if((ch == 'n') || (ch == 'N')){
                break;
            }
        }//避免死循环
    } while (num >= 0);
    del(head);
}
Read more »