事情有点多,简单写了一些代码。
<!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>
</head>
<body>
<div id="app">
<div class="input-num">
<button @click="sub">-</button>
<span>{{num}}</span>
<button @click="add">+</button>
</div>
</div>
<!-- 开发环境版本,包含了有帮助的命令行警告 -->
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
var app = new Vue({
el: "#app",
data: {
num: 1
},
methods: {
add: function () {
if (this.num < 10)
this.num++;
else
alert("sorry~");
console.log('add');
},
sub: function () {
console.log('sub');
if (this.num > 0) {
this.num--;
} else {
alert("Don't click me!");
}
}
}
})
</script>
</body>
</html>
这是一个网页上的0-10的计时器
课堂上写了一个在二维空间上输入n个点,并找出最大距离的两个点的题目。
#include<iostream>
#include<math.h>
#include<iomanip>
using namespace std;
class Point {
double x, y;
public:
Point() {};
Point(double x, double y) {
this->x = x;
this->y = y;
}
void set(double x, double y) {
cout << "Constructor."<<endl;
this->x = x;
this->y = y;
}
double get(Point&p) {
return sqrt(((x - p.x)) * (x - p.x) + (y - p.y) * (y - p.y));
}
~Point() {
cout << "Distructor." << endl;
}
};
int main() {
int all;
cin >> all;
for (int i = 0; i < all; i++) {
int num;
cin >> num;
Point* p = new Point[num];
for (int i = 0; i < num; i++) {
double x, y;
cin >> x >> y;
p[i].set(x, y);
}
double max = 0;
int x1, x2;
for (int i = 0; i < num - 1; i++) {
for (int j = i + 1; j < num; j++) {
double t;
t = p[i].get(p[j]);
if (t < 0)
t = -t;
if (t > max) {
x1 = i;
x2 = j;
max = t;
}
}
}
cout << "The longeset distance is " << fixed << setprecision(2) << max << ",between p[" << x1 << "] and p[" << x2 << "]." << endl;
delete[]p;
}
}
感觉这道题还是很有意思的