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

eee #47

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open

eee #47

Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 27 additions & 0 deletions level1/p01_runningLetter/runningLetter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
int LENGTH = 70;
int main(){
int k, i = 1, l, p;
while (i++){
if (i > LENGTH)l = i % LENGTH;
else l = i;
p = i / LENGTH;
if (p % 2 == 0){
for (k = 1; k < l - 1; k++){
printf_s(" ");
}
printf_s("->");
}
if (p % 2 == 1){
for (k = 1; k < LENGTH - l - 1; k++) {
printf_s(" ");
}
printf_s("<-");
}
Sleep(50);
system("cls");
}
return 0;
}
26 changes: 26 additions & 0 deletions level1/p02_isPrime/isPrime.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include<stdio.h>
#include<math.h>
void isPrime(int a){
int b;
b = int(sqrt(a));
if (b == 1)printf_s("Yes\n");
else
for (int i = 2; i <= b; i++){
if (a % i == 0){
printf_s("No\n");
break;
}
else if (i == b)printf_s("Yes\n");
}
}
int main(){
int a;
start:
Copy link
Owner

Choose a reason for hiding this comment

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

还是改为while循环好点

printf_s("请输入一个大于1的整数(输入1退出):");
scanf_s("%d", &a);
if (a != 1){
isPrime(a);
goto start;
}
if(a==1) return 0;
}
12 changes: 12 additions & 0 deletions level1/p03_Diophantus/源.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#include<stdio.h>
int main(){
float y = 9.000;
while (y+=1){
float t = y * (1.000 / 6.000 + 1.000 / 12.000 + 1.000 / 7.000) + 9;
if (t * 2== y){
printf_s("����ͼ��ʱ�������ǣ�%d", int(y));
Copy link
Owner

Choose a reason for hiding this comment

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

文件的编码改为utf-8,这样就不会有乱码了

break;
}
}
return 0;
}
14 changes: 14 additions & 0 deletions level1/p04_ narcissus/源.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include<stdio.h>
#include<math.h>
int main(){
int n, a, b, c;
int m;
for (n = 100; n < 1000; n++){
a = n / 100;
m = n % 100;
b = m / 10;
c = m % 10;
if (pow(a, 3) + pow(b, 3) + pow(c, 3) == n)printf_s("%d ", n);
}
return 0;
}
16 changes: 16 additions & 0 deletions level1/p05_allPrimes/源.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<stdio.h>
int main(){
int m[1000] = { 0, 2 };
int i, n = 1;
for (i = 2; i <= 1000; i++){
for (int k = 1; k <= n; k++){
if (i % m[k] == 0)break;
else if (k == n){
n++;
m[n] = i;
printf_s("%d ", i);
}
}
}
return 0;
}
22 changes: 22 additions & 0 deletions level1/p06_Goldbach/源.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
int main()
{
int x, y;
int p[] = { 0,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97 };
bool t;
for (int i = 4; i <= 100; i += 2){
t = false;
for (x = 1; x <= 25; x++){
for (y = 1; y <= 25; y++){
if ((p[x] + p[y]) == i){
t = true;
break;
}
}
if (t == true)break;
}
if (t == false)printf_s("��°ͺղ�����100���ڲ�����,%d");
}
if (t == true)printf_s("��°ͺղ�����100���ڳ���");
return 0;
}
27 changes: 27 additions & 0 deletions level1/p07_encrypt_decrypt/源.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include<stdio.h>
#include<conio.h>
char CODE[2][95] =
{{" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"},
{"xA.KU2g!OrRyu]p8E;s&1`5HCD{jXlz_}|vo:)Y%f9Bawh $W(\"4cq\*NL-kI/Q?b'J=^d,Z[FGntP+#Vie<>m@TS~70M36"}};
void func(char c[1000]){
int i = 0, a, b;
if (c[0] == 'e')a = 0;
if (c[0] == 'd')a = 1;
while (c[i] != '\0'){
for (int k = 0; k < 95; k++) {
if (c[i] == CODE[a][k]) {
printf_s("%c", CODE[1 - a][k]);
break;
}
}
i++;
}
}
int main() {
int i = 0;
printf_s("�������루��������e��ͷ����������d��ͷ����\n");
char c[1000] = { '\0' };
gets_s(c);
func(c);
return 0;
}
22 changes: 22 additions & 0 deletions level1/p08_hanoi/源.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include<stdio.h>
long int s = 0;
void move(int a, int start, int end) {
if (a == 1) {
printf_s("%d->%d\n", start, end);
s++;
}
else {
move(a - 1, start, 6 - start - end);
printf_s("%d->%d\n", start, end);
s++;
move(a - 1, 6 - start - end, end);
Copy link
Owner

Choose a reason for hiding this comment

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

6-start-end 这个技巧不错,可以抽一个局部变量来存,避免计算两次;
这个技巧的缺点是,稍稍有点破坏代码的可读性

}
}
int main() {
int a;
printf_s("������Ҫ�ƶ��ĸ���");
scanf_s("%d", &a);
move(a, 1, 2);
printf_s("�ܹ��ƶ�%l��", s);
return 0;
}
2 changes: 2 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hello
sadfaiiiiiiiiiisd