forked from newde/homework
Compare commits
16 Commits
233b470060
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 9c8894defc | |||
| 0087ebeeb0 | |||
| e286827623 | |||
| da93e118a0 | |||
| 8a2a2252d1 | |||
| 0beed8b222 | |||
| e455b2f368 | |||
| 57545f3e87 | |||
| 8df4fbee32 | |||
| 60743f8e32 | |||
| e26524c970 | |||
| d38936ae32 | |||
| e3559ded14 | |||
| b69a67b7b5 | |||
| d9c243164f | |||
| 4e99c003dd |
45
20260321
Normal file
45
20260321
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
// 判断是否是素数
|
||||||
|
bool isPrime(int n)
|
||||||
|
{
|
||||||
|
if (n < 2) return false;
|
||||||
|
|
||||||
|
for (int i = 2; i * i <= n; i++)
|
||||||
|
{
|
||||||
|
if (n % i == 0)
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 判断是否是回文数
|
||||||
|
bool isPalindrome(int n)
|
||||||
|
{
|
||||||
|
int original = n;
|
||||||
|
int reversed = 0;
|
||||||
|
|
||||||
|
while (n > 0)
|
||||||
|
{
|
||||||
|
reversed = reversed * 10 + n % 10;
|
||||||
|
n /= 10;
|
||||||
|
}
|
||||||
|
|
||||||
|
return original == reversed;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
cout << "100到1000之间的回文素数有:" << endl;
|
||||||
|
|
||||||
|
for (int i = 100; i <= 1000; i++)
|
||||||
|
{
|
||||||
|
if (isPrime(i) && isPalindrome(i))
|
||||||
|
{
|
||||||
|
cout << i << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
21
260202/会场人数计算.cpp
Normal file
21
260202/会场人数计算.cpp
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
//会场总共312人,第一排15人后一排比前一排多2人,求共有多少排,最后一排的人数。
|
||||||
|
|
||||||
|
1 #include<iostream>
|
||||||
|
2 using namespace std;
|
||||||
|
3
|
||||||
|
4 int main(){
|
||||||
|
5
|
||||||
|
6 int p=1,x,sum;
|
||||||
|
7 x=15;
|
||||||
|
8 sum=x;
|
||||||
|
9 while(sum<312){
|
||||||
|
10 p+=1;
|
||||||
|
11 x+=2;
|
||||||
|
12 sum=sum+x;
|
||||||
|
13
|
||||||
|
14 cout<< "剧场有"<<p<<"排,"<<"最后一排有"<<x<<"人!"<<"共有"<<sum<<"人!"<<endl;
|
||||||
|
15 }
|
||||||
|
16
|
||||||
|
17 return 0;
|
||||||
|
18
|
||||||
|
19 }
|
||||||
26
260321/100以内的素数.cpp
Normal file
26
260321/100以内的素数.cpp
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#include <iostream>
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
for (int n = 2; n <= 100; n++) {
|
||||||
|
bool x = true;
|
||||||
|
// i*i <=n因数是成对出现的任何一个合数 ,都可以写成两个数相乘:
|
||||||
|
//n = a * b
|
||||||
|
//比如 n = 16,它的因数对有:
|
||||||
|
//2 * 8 = 16
|
||||||
|
//4 * 4 = 16
|
||||||
|
//8 * 2 = 16
|
||||||
|
|
||||||
|
for (int i = 2; i * i <= n; i++) {
|
||||||
|
if (n % i == 0) {
|
||||||
|
x = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x) {
|
||||||
|
cout << n << " ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
26
config.yaml
Normal file
26
config.yaml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
server_url: https://hs.yihaoai.cc
|
||||||
|
listen_addr: 0.0.0.0:8080
|
||||||
|
metrics_listen_addr: 127.0.0.1:9090
|
||||||
|
grpc_listen_addr: 0.0.0.0:50443
|
||||||
|
grpc_allow_insecure: false
|
||||||
|
noise:
|
||||||
|
private_key_path: /var/lib/headscale/noise_private.key
|
||||||
|
prefixes:
|
||||||
|
v4: 100.64.0.0/10
|
||||||
|
v6: fd7a:115c:a1e0::/48
|
||||||
|
derp:
|
||||||
|
server:
|
||||||
|
enabled: false
|
||||||
|
urls:
|
||||||
|
- https://controlplane.tailscale.com/derpmap/default
|
||||||
|
database:
|
||||||
|
type: sqlite3
|
||||||
|
sqlite:
|
||||||
|
path: /var/lib/headscale/db.sqlite
|
||||||
|
dns:
|
||||||
|
magic_dns: true
|
||||||
|
base_domain: yihaoai.local
|
||||||
|
nameservers:
|
||||||
|
global:
|
||||||
|
- 114.114.114.114
|
||||||
|
- 8.8.8.8
|
||||||
16
指针/交换值 .cpp
Normal file
16
指针/交换值 .cpp
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
1 #include<iostream>
|
||||||
|
2 using namespace std;
|
||||||
|
3
|
||||||
|
4 int main(){
|
||||||
|
5 int a=10,b=5,temp,*ptr_a,*ptr_b;
|
||||||
|
6 cout<<"a的值是:"<<a<<" b的值是:"<<b<<endl;
|
||||||
|
7 ptr_a=&a;
|
||||||
|
8 ptr_b=&b;
|
||||||
|
9 temp=*ptr_a;
|
||||||
|
10 *ptr_a=*ptr_b;
|
||||||
|
11 *ptr_b=temp;
|
||||||
|
12
|
||||||
|
13 cout<<"交换后a的值是:"<<a<<" b的值是:"<<b<<endl;
|
||||||
|
14
|
||||||
|
15 return 0;
|
||||||
|
16 }
|
||||||
20
指针/指针和数组的地址.cpp
Normal file
20
指针/指针和数组的地址.cpp
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
1 #include<iostream>
|
||||||
|
2 using namespace std;
|
||||||
|
3
|
||||||
|
4 int main(){
|
||||||
|
5
|
||||||
|
6 int a=10;
|
||||||
|
7 int b[5]={10,20,30,40,50};
|
||||||
|
8 int * ptr_a , * ptr_b;
|
||||||
|
9
|
||||||
|
10 ptr_a=&a;
|
||||||
|
11 ptr_b=b;
|
||||||
|
12 cout << "我是内存地址: "<<ptr_a <<" 我是地址内的值 : "<< * ptr_a<<endl;
|
||||||
|
13 cout << "我是内存地址: "<<ptr_b <<" 我是地址内的值 : "<< * ptr_b<<endl;
|
||||||
|
14
|
||||||
|
15 for (int i=0;i<5;i++)
|
||||||
|
16 cout << "我的地址:"<< ptr_b+i<<endl;
|
||||||
|
17
|
||||||
|
18 return 0;//这个可以省略
|
||||||
|
19
|
||||||
|
20 }
|
||||||
14
指针/指针地址.cpp
Normal file
14
指针/指针地址.cpp
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
1 #include<iostream>
|
||||||
|
2 using namespace std;
|
||||||
|
3
|
||||||
|
4 int main(){
|
||||||
|
5
|
||||||
|
6 int a=10;
|
||||||
|
7 int * ptr_a ;
|
||||||
|
8
|
||||||
|
9 ptr_a=&a;
|
||||||
|
10 cout << "我是内存地址: "<<ptr_a <<" 我是地址内的值 : "<< * ptr_a<<endl;
|
||||||
|
11
|
||||||
|
12 return 0;//这个可以省略
|
||||||
|
13
|
||||||
|
14 }
|
||||||
19
指针/求最大值 .cpp
Normal file
19
指针/求最大值 .cpp
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
1 #include<iostream>
|
||||||
|
2 using namespace std;
|
||||||
|
3
|
||||||
|
4 int main(){
|
||||||
|
5 int max,*ptr;
|
||||||
|
6 int arr[5]={10,20,33,15,11};
|
||||||
|
7 max = arr[0];
|
||||||
|
8 ptr = arr;
|
||||||
|
9
|
||||||
|
10 for (int i = 0; i < 5; i++) {
|
||||||
|
11 if (*ptr > max) {
|
||||||
|
12 max = *ptr;
|
||||||
|
13 }
|
||||||
|
14 ptr++;
|
||||||
|
15 }
|
||||||
|
16 cout << "最大值是:"<< max<<endl;
|
||||||
|
17
|
||||||
|
18 return 0;
|
||||||
|
19 }
|
||||||
Reference in New Issue
Block a user