Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成了running letter #32

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bec1370
完成了running letter
Mar 2, 2019
3f73640
Level 1 Exercise 2
C-ice-y Mar 20, 2019
2ac63b7
Level 1Exercise 3
C-ice-y Mar 20, 2019
bf75807
Level 1 Exercise 4
C-ice-y Mar 20, 2019
e26d96d
Level1 Exercise 1 update
C-ice-y Mar 20, 2019
5f014e1
level1 Exercise5
C-ice-y Mar 25, 2019
2356fcb
Update README.md
C-ice-y Mar 25, 2019
4cdf1fc
Level1 Exercise6
C-ice-y Mar 25, 2019
bd24ae4
Update L1T4.cpp
C-ice-y Mar 27, 2019
1ec64ee
Update L1T5.cpp
C-ice-y Mar 27, 2019
9da8788
Update L1T3.cpp
C-ice-y Mar 27, 2019
549129c
Exercise L1T8
C-ice-y Apr 3, 2019
5f1fe82
Update README.md
C-ice-y Apr 3, 2019
3f3305a
Add files via upload
C-ice-y Jun 23, 2019
7e340fa
Add files via upload
C-ice-y Jun 23, 2019
d214aba
Add files via upload
C-ice-y Jun 23, 2019
dc210c8
Add files via upload
C-ice-y Jun 23, 2019
2b737f7
Create FiveChess
C-ice-y Jun 23, 2019
2530e96
Delete FiveChess
C-ice-y Jun 23, 2019
c9d8dfc
Add files via upload
C-ice-y Jun 23, 2019
da9cf3b
Delete 五子棋txt.txt
C-ice-y Jun 23, 2019
fbcfb3e
Delete thoughts of WUZIQI.txt
C-ice-y Jun 23, 2019
d3243b1
Add files via upload
C-ice-y Jun 23, 2019
ad0faa3
Add files via upload
C-ice-y Jun 23, 2019
244422f
Delete mazeutf.txt
C-ice-y Jun 26, 2019
67c075d
Add files via upload
C-ice-y Jun 26, 2019
517d040
Delete 推箱子utf.txt
C-ice-y Jun 26, 2019
da4f9c9
Add files via upload
C-ice-y Jun 26, 2019
9412054
Delete 链表.txt
C-ice-y Jun 26, 2019
9fae957
Add files via upload
C-ice-y Jun 26, 2019
650d8d0
Delete utf超市.txt
C-ice-y Jun 26, 2019
ad232b9
Add files via upload
C-ice-y Jun 26, 2019
d3ec29a
Add files via upload
C-ice-y Jun 26, 2019
07311d7
Update 五子棋txt.txt
C-ice-y Jun 26, 2019
a8d0c59
Update 五子棋txt.txt
C-ice-y Jun 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions level1/p01_runningLetter/L1T1.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define Length 20
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一般常量用全大写


int main ()
{
int a=0;
int b=1;
while(1)
{
a+=b;
system("cls");
int i=0;
while(i<a)
{
printf(" ");
i++;
}
printf("H");
Sleep(100);
if(a==Length)
{
b=-1;
}
if(a==0)
{
b=1;
}
}
return 0;
}




33 changes: 33 additions & 0 deletions level1/p01_runningLetter/L1T4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>
#define LENGTH 20

int main ()
{
int a=0;
int b=1;
while(1)
{
a+=b;
system("cls");
int i=0;
while(i<a)
{
printf(" ");
i++;
}
printf("H");
Sleep(100);
if(a==Length)
{
b=-1;
}
if(a==0)
{
b=1;
}
}
return 0;
}

26 changes: 26 additions & 0 deletions level1/p02_isPrime/L1T2.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <stdio.h>
int main()
{
unsigned int a;
printf("��������һ��������:");
scanf("%u",&a);
int i,b=0;
for(i=1;i<=a;i++)
{
if(a%i==0)
{
b++;
}
}
if(b==2||b==1)
{
printf("%u��������\n",a);
}
else
{
printf("%u����������\n",a);
}

return 0;
}

16 changes: 16 additions & 0 deletions level1/p03_Diophantus/L1T3.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


#include <stdio.h>
int main()
{
int age;
for(age=1;;age++)
{
if(age*1.0/6+age*1.0/12+age*1.0/7+5+4==age*1.0/2)
{
age-=4;
printf("����ͼ������ʱ����ͼ%d�ꡣ",age);
break;
}
}
}
17 changes: 17 additions & 0 deletions level1/p04_ narcissus/L1T4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
int main()
{
int hun,dec,uni,med,nar;
for(med=100;med<=999;med++)
{
hun=med/100;
dec=(med-(hun*100))/10;
uni=(med-(hun*100)-dec*10);
nar=hun*hun*hun+dec*dec*dec+uni*uni*uni;
if (nar==med)
{
printf("%d ",nar);
}
}
printf("\n");
}
43 changes: 43 additions & 0 deletions level1/p05_allPrimes/L1T5.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include<stdio.h>
#include <math.h>
#include <Windows.h>
void CreatePrime(int *primes, int n)
{
int i, j, s;
primes[0] = primes[1] = 0;
for(i = 2; i < n; i++)
primes[i] = 1;
s = sqrt(n);
for(i = 2; i<= s; i++)
{
if(primes[i])
{
for(j = 2 * i; j < n; j+=i)
primes[j] = 0;
}
}
}
int main()
{
int i;
double run_time;
LARGE_INTEGER time_start;
LARGE_INTEGER time_over;
double dqFreq;
LARGE_INTEGER f;
QueryPerformanceFrequency(&f);
dqFreq=(double)f.QuadPart;
QueryPerformanceCounter(&time_start);
int IsPrime[1000];
CreatePrime(IsPrime, 1000);
for(i = 2; i < 1000; i++)
if(IsPrime[i])
{
printf("%d\t",i);
}
QueryPerformanceCounter(&time_over);
run_time=1000000*(time_over.QuadPart-time_start.QuadPart)/dqFreq;
printf("\nrun_time��%fus\n",run_time);
return 0;
}

3 changes: 2 additions & 1 deletion level1/p05_allPrimes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

1. 打印2-1000以内的所有素数
1. 打印出总的计算时间
1. 尽可能优化算法的效率
1. 尽可能优化算法的效率
//
59 changes: 59 additions & 0 deletions level1/p06_Goldbach/L1T6.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include <stdio.h>

int isPrime(int n);

int main()
{
int i = 0;
int j = 0;
int k1 = 0;
int k2 = 0;
int even[50];
int ret1 = 0;
int ret2 = 0;
int count = 0;
for(i=4;i<=100;i+=2)
{
count = 0;
j = i;
k1 = j-1 ;
while(k1>=(j/2))
{
ret1 = isPrime(k1);
if(ret1)
{
k2 = j - k1;
ret2 = isPrime(k2);
if(ret2)
{
printf("%d = %d + %d,", j, k2, k1);
count ++;
}
}
k1--;
}
printf("%d���Բ��Ϊ%d�飡\n", i, count);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文件的encoding需要用utf-8,这样就不会乱码了


}
return 0;
}
int isPrime(int n)
{
int i = 0;
if(n<=1)
{
return 0;
}
if(2==n)
{
return 1;
}
for(i=2;i<n;i++)
{
if(0==n%i)
{
return 0;
}
}
return 1;
}
121 changes: 121 additions & 0 deletions level1/p07_encrypt_decrypt/加密解密.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/* 我用的凯撒加密*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
//函数encrypt()将字母顺序推后n位,实现文件加密功能
void encrypt(char str[],int n)
{
char c;
int i;
for(i=0;i<strlen(str);++i)
{
c=str[i];
if(c>='a' && c<='z')//c是小写字母
{
if(c+n%26<='z') //若加密后不超出小写字母范围
{
str[i]=(char)(c+n%26); //加密函数
}
else
{
str[i]=(char)(c+n%26-26);//加密后超出小写字母范围,从头开始循环小写字母
}
}
else if(c>='A' && c<='Z')//c为大写字母
{
if(c + n%26 <= 'Z') //加密后不超出大写字母范围
{
str[i]=(char)(c+n%26);
}
else
{
str[i]=(char)(c+n%26-26);//加密后超出大写字母范围,从头开始循环大写字母
}
}
else
{
str[i]=c;//不是字母,不加密
}
}
printf("\nAfter encrypt: \n");
puts(str); //输出加密后的字符串
}


//decrypt()实现解密功能,将字母顺序前移n位
void decrypt(char str[],int n)
{
char c;
int i;
//遍历字符串
for(i=0;i<strlen(str);++i)
{
c=str[i]; //c为小写字母
if(c>='a' && c<='z')
{

if(c-n%26>='a') //解密后还为小写字母,直接解密
{
str[i]=(char)(c-n%26);
}
else
{

str[i]=(char)(c-n%26+26); //解密后不为小写字母了,通过循环小写字母处理为小写字母
}
}
else if(c >= 'A' && c<='Z') //c为大写字母
{
if(c-n%26>='A') //解密后还为大写字母
{
str[i]=(char)(c-n%26);
}
else
{
str[i]=(char)(c-n%26+26); //解密后不为大写字母了,循环大写字母,处理为大写字母
}
else
{
str[i]=c; //非字母不处理
}
}
printf("\nAfter decrypt: \n");
puts(str); //输出解密后的字符串
}

int main()
{
char str[50];
int k=0,n=0,i=1;
printf("\nPlease input strings: ");
scanf("%s",str); //输入加密解密字符串
//打印菜单
printf("-----------------\n");
printf("1: Encryption\n");
printf("2: Decryption\n");
printf("3: Violent Crack\n"); //暴力破解
printf("-----------------\n");
printf("\nPlease choose: ");
scanf("%d",&k);
if(k==1)
{
printf("\nPlease input number: ");
scanf("%d",&n);
encrypt(str,n);
}
else if(k==2)
{
printf("\nPlease input number: ");
scanf("%d",&n);
decrypt(str,n);
}
else
{
for(i=1;i<=25;++i)
{
printf("%d ",i); //尝试所有可能的n值进行暴力破解
decrypt(str,i);
}
}
return 0;
}
11 changes: 10 additions & 1 deletion level1/p08_hanoi/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,13 @@

1.汉诺塔:汉诺塔(又称河内塔)问题是源于印度一个古老传说的益智玩具。大梵天创造世界的时候做了三根金刚石柱子,在一根柱子上从下往上按照大小顺序摞着64片黄金圆盘。大梵天命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上。并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一次只能移动一个圆盘。

![](./hanoi.jpg)
![](./hanoi.jpg)
思路:1.把 n-1个盘子先移动到2号底座
2.把1号底座上剩下的一个盘子移动到3号底座上
3.再把n-1个盘子从2号底座移动到3号底座上
递归思想的理解:

1.递归奠基。先考虑最基本的情况,即无需递归就能解出的情况,弄清楚变量的去向和作用。
2.递归奠基推进。从最基本的情况一步步走向递归来解决,每一次递归调用都让结果更接近目标。
3.桥梁架构。假设所有的递归调用都能运行。
4.高效应用。力求每一步调用都让结果更接近目标,不做无用功。
Loading