Skip to content

Commit b2a161c

Browse files
committed
第七题
1 parent 0456030 commit b2a161c

File tree

869 files changed

+40487
-13
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

869 files changed

+40487
-13
lines changed

lwh/7/line_counter.py

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,57 @@
22
有个目录,里面是你自己写过的程序,统计一下你写过多少行代码。
33
包括空行和注释,但是要分别列出来。
44
"""
5-
5+
# -*- coding:gbk -*-
66
import os
77
import re
88

9-
root_dir = os.getcwd() + "//1001"
10-
code_lines = 0
11-
blank_lines = 0
12-
annotation_lines = 0
9+
root_dir = os.getcwd() + "/卢炜豪"
10+
os.chdir(root_dir)
11+
12+
code_count = 0
13+
note_count = 0
14+
15+
16+
def isnote(line):
17+
line = line.strip()
18+
#print(line, line_count)
19+
if len(line) >= 2:
20+
# print("***")
21+
#print("&&&", line[0], line[1])
22+
if line[0] == 47 and line[1] == 47:
23+
return "//"
24+
elif line[0] == 47 and line[1] == 42:
25+
return "/*"
26+
else:
27+
return "no"
28+
29+
for parent, dirnames, filenames in os.walk(root_dir):
30+
#print(parent, filenames)
31+
# print(dirname)
32+
33+
for filename in filenames:
34+
os.chdir(parent)
35+
print(filename)
36+
print(parent)
37+
with open(filename, "rb") as f:
38+
line = f.readline().strip()
39+
while line != b"":
40+
print("*")
41+
ret = isnote(line)
42+
print(ret)
43+
if ret == "//":
44+
note_count = note_count + 1
45+
elif ret == "/*":
46+
line = f.readline().strip()
47+
print(line)
48+
# if len(line) >= 2:
49+
while b"*/" in line:
50+
note_count = note_count + 1
51+
line = f.readline().strip()
52+
print(line)
53+
elif ret == "no":
54+
code_count = code_count + 1
55+
line = f.readline().strip()
1356

14-
for root, dirs, files in os.walk(root_dir):
15-
for i in files:
16-
print(root_dir + "\\" + i)
17-
with open(root_dir + "\\" + i, "r", encoding="utf-8") as f:
18-
line = f.readline()
19-
while line != "":
20-
print(line)
21-
line = f.readline()
57+
print("代码行数:%d" % code_count)
58+
print("注释函数 %d" % note_count)

lwh/7/卢炜豪/10001/257420.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*先用筛法求出6-10000之间的所有素数,存进一个数组中,
2+
输入一个测试的数据,用for进行枚举,得到离这个数据最接近又小于他的一个素数,。。不说了先写代码看看会不会超时先
3+
*/
4+
#include<stdio.h>
5+
#include<string.h>
6+
#include<math.h>
7+
#define maxn 100000000
8+
int prime[maxn],isprime[maxn];
9+
int main()
10+
{
11+
int x;
12+
scanf("%d",&x);
13+
int cnt=2;
14+
long long int edge=x*x;
15+
memset(prime,0,sizeof(prime));
16+
memset(isprime,0,sizeof(isprime));
17+
// printf("%d",prime[199]);
18+
prime[0]=0;
19+
prime[1]=0;
20+
prime[2]=0;
21+
for(int i=2;i*i<edge;i++)
22+
{
23+
// printf("i=%d\n",i);
24+
if(prime[i]==0)
25+
{
26+
isprime[cnt]=i;
27+
printf("isprime[%d]=%d\n",cnt,isprime[cnt]);
28+
cnt++;
29+
}
30+
for(int j=i*i;j<edge&&j>=0;j=j+i)
31+
{
32+
prime[j]=1;
33+
// printf("i=%d j=%d i*j=%d\n",i,j,i*j);
34+
}
35+
}
36+
37+
}

lwh/7/卢炜豪/10001/258027.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
5+
#define max 100005
6+
7+
int prime[max];
8+
int book[max];
9+
int check[max];
10+
11+
int main()
12+
{
13+
int tot=0;
14+
memset(check,0,sizeof(check));
15+
memset(book,1,sizeof(book));
16+
for(int i=2;i<max;++i)
17+
{
18+
if(check[i]==0)
19+
{
20+
21+
prime[tot]=i;
22+
book[i]=0;
23+
// printf("tot=%d %d\n",tot,prime[tot]);
24+
tot++;
25+
}
26+
for(int j=0;j<tot;++j)
27+
{
28+
if(i*prime[j]>max)
29+
break;
30+
check[i*prime[j]]=1;
31+
if(i%prime[j]==0)
32+
break;
33+
}
34+
}
35+
/* for(int i=0;i<561;i++)
36+
printf("check[%d]=%d prime[%d]=%d book[%d]=%d\n",i,check[i],i,prime[i],i,book[i]);
37+
printf("q=%d\n",q);
38+
*/
39+
// printf("%d\n",prime[3]);
40+
//素数表构建完成,接下来进行歌德巴赫输出
41+
42+
int n,i,j,left1,right1;
43+
while(scanf("%d",&n)!=EOF)
44+
{
45+
int left,right,plus;
46+
for(left=3,right=n-left;left<=n/2;left++,right=n-left)
47+
{
48+
// printf("left=%d right=%d\n",left,right);
49+
if(book[left]==0&&book[right]==0&&left+right==n)
50+
{
51+
left1=left;
52+
right1=right;
53+
// printf("~plus=%d and %d %d\n\t",plus,left,right);
54+
}
55+
}
56+
printf("%d %d\n",left1,right1);
57+
58+
}
59+
60+
61+
}

lwh/7/卢炜豪/10001/258028.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
5+
#define max 100005
6+
7+
int prime[max];
8+
int book[max];
9+
int check[max];
10+
11+
int main()
12+
{
13+
int tot=0;
14+
memset(check,0,sizeof(check));
15+
memset(book,1,sizeof(book));
16+
for(int i=2;i<max;++i)
17+
{
18+
if(check[i]==0)
19+
{
20+
21+
prime[tot]=i;
22+
book[i]=0;
23+
// printf("tot=%d %d\n",tot,prime[tot]);
24+
tot++;
25+
}
26+
for(int j=0;j<tot;++j)
27+
{
28+
if(i*prime[j]>max)
29+
break;
30+
check[i*prime[j]]=1;
31+
if(i%prime[j]==0)
32+
break;
33+
}
34+
}
35+
/* for(int i=0;i<561;i++)
36+
printf("check[%d]=%d prime[%d]=%d book[%d]=%d\n",i,check[i],i,prime[i],i,book[i]);
37+
printf("q=%d\n",q);
38+
*/
39+
// printf("%d\n",prime[3]);
40+
//素数表构建完成,接下来进行歌德巴赫输出
41+
42+
int n,i,j,left1,right1;
43+
while(scanf("%d",&n)!=EOF)
44+
{
45+
int left,right;
46+
left=n/2;
47+
right=n-left;
48+
for(;left>0;left--,right=n-left)
49+
{
50+
if(book[left]==0&&book[right]==0&&right+left==n)
51+
{
52+
printf("%d %d\n",left,right);
53+
break;
54+
}
55+
}
56+
57+
}
58+
59+
60+
}

lwh/7/卢炜豪/10001/258029.cpp

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#include <stdio.h>
2+
#include <string.h>
3+
4+
5+
#define max 50005
6+
7+
int prime[max];
8+
int book[max];
9+
int check[max];
10+
11+
int main()
12+
{
13+
int tot=0;
14+
memset(check,0,sizeof(check));
15+
memset(book,1,sizeof(book));
16+
for(int i=2;i<max;++i)
17+
{
18+
if(check[i]==0)
19+
{
20+
21+
prime[tot]=i;
22+
book[i]=0;
23+
// printf("tot=%d %d\n",tot,prime[tot]);
24+
tot++;
25+
}
26+
for(int j=0;j<tot;++j)
27+
{
28+
if(i*prime[j]>max)
29+
break;
30+
check[i*prime[j]]=1;
31+
if(i%prime[j]==0)
32+
break;
33+
}
34+
}
35+
/* for(int i=0;i<561;i++)
36+
printf("check[%d]=%d prime[%d]=%d book[%d]=%d\n",i,check[i],i,prime[i],i,book[i]);
37+
printf("q=%d\n",q);
38+
*/
39+
// printf("%d\n",prime[3]);
40+
//素数表构建完成,接下来进行歌德巴赫输出
41+
42+
int n,i,j,left1,right1;
43+
while(scanf("%d",&n)!=EOF)
44+
{
45+
int left,right;
46+
left=n/2;
47+
right=n-left;
48+
for(;left>0;left--,right=n-left)
49+
{
50+
if(book[left]==0&&book[right]==0&&right+left==n)
51+
{
52+
printf("%d %d\n",left,right);
53+
break;
54+
}
55+
}
56+
57+
}
58+
59+
60+
}

lwh/7/卢炜豪/10002/247093.cpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#include<stdio.h>
2+
#include<string.h>
3+
#define maxn 65540
4+
int main()
5+
{
6+
//先用筛法求出素数表,放进数组prime中
7+
//1表示是素数,0表示表示不是素数
8+
9+
int prime[maxn],isprime[maxn],i,j;//先假设全部都是素数
10+
int n=266;
11+
for(int i=0;i<n;i++)
12+
prime[i]=1;
13+
for(int i=2;i<n;i++)
14+
{
15+
//printf("~");
16+
if(prime[i]==1)
17+
{
18+
for(int j=i;j<n;j++)
19+
{
20+
prime[j*i]=0;
21+
//printf("!");
22+
23+
}
24+
}
25+
}
26+
j=1;
27+
for(int i=1;i<n;i++)
28+
{
29+
30+
if(prime[i]==1)
31+
{
32+
33+
isprime[j]=i;
34+
j++;
35+
36+
}
37+
}
38+
//for(i=1;i<j;i++) printf("%d\n",isprime[i]);
39+
40+
//以上代码求得素数表isprime
41+
// printf("!%d\n",isprime[5]);
42+
int x,q=2;
43+
while(scanf("%d",&x)!=EOF)
44+
{
45+
46+
// scanf("%d",&x);
47+
int p=x;
48+
// for(int i=1;i<)
49+
50+
for(q=2;isprime[q]<x;q++)
51+
{
52+
while(x!=isprime[q])
53+
{
54+
if(x%isprime[q]==0)
55+
{
56+
//if(p==isprime[q]) printf("1");
57+
printf("%d ",isprime[q]);
58+
x=x/isprime[q];
59+
}
60+
else
61+
break;
62+
}
63+
64+
65+
66+
}
67+
if(x==p)
68+
printf("1 %d\n",x);
69+
else printf("%d\n",x);
70+
}
71+
72+
73+
74+
75+
}

0 commit comments

Comments
 (0)