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 #37

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
29 changes: 29 additions & 0 deletions practices/c/level1/p01_runningLetter/p01_running_letter.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<stdio.h>
#include<windows.h>
#define TIMES 50
int main(void)
{
int i,j;

for(i=1;i<TIMES;i++)
{
for(j=1;j<i;j++)
{
printf(" ");
}
printf("R");
Sleep(200);
system("cls");
}
for(i=TIMES;i>0;i--)
Copy link
Owner

Choose a reason for hiding this comment

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

Smell!闻到了重复的味道!请设法消除它

{
for(j=1;j<i;j++)
{
printf(" ");
}
printf("R");
Sleep(200);
system("cls");
}
return 0;
}
23 changes: 23 additions & 0 deletions practices/c/level1/p02_isPrime/p02_isPrime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <stdio.h>
int main(void)
{
int num;
int i,j;

printf("����һ����������");
while((scanf("%d",&num)==1))
{
for(i=2,j=1;(i*i)<num;i++)
{
if(num%i==0)
{
printf("%d��������.\n",num);
j=0;
break;
}
}
if(j==1)
printf("%d������",num);
}
return 0;
}
17 changes: 17 additions & 0 deletions practices/c/level1/p03_Diophantus/p03_Diophantus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include <stdio.h>
int main(void)
{
float years=0;
float childhood,young,single;

while(years<200)
{
childhood=(float)years/6;
young=(float)years/7;
single=(float)years/12;
if(years==(childhood+young+single+5+4)*2)
printf("������ʱ����ͼΪ%d��.\n",(int)years-4);
years++;
}
return 0;
}
18 changes: 18 additions & 0 deletions practices/c/level1/p04_ narcissus/p04_ narcissus.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include <stdio.h>
int main(void)
{
int a,b,c;
int num;

for(a=1;a<=9;a++){
for(b=0;b<=9;b++){
for(c=0;c<=9;c++){
num=a*100+b*10+c;
if(num==(a*a*a+b*b*b+c*c*c)){
printf("%d\n",num);
}
}
}
}
return 0;
}
24 changes: 24 additions & 0 deletions practices/c/level1/p05_allPrimes/p05-allPrimes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>
#include <time.h>
int main(void)
{
int num=1000;
int i,j,div;
int x,y;

x=clock();
for(i=2;i<=num;i++)
{
for(div=2,j=1;(div*div)<i;div++)
{
if(i%div==0)
break;
}
if((div*div)>i)
printf("%5d",i);
}
y=clock();
printf("�ܵļ���ʱ��Ϊ��%d",y-x);

return 0;
}
179 changes: 179 additions & 0 deletions practices/c/level1/p09_maze/Maze.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#ifndef MZAE_H
#define MAZE_H
#include <stdio.h>
#include <conio.h>
#include <windows.h>

/*���ļ��д򿪵�ͼ*/
void open(char *filename);

/*��ӭ����*/
void hello(void);

/*��ʾ��ͼ*/
void show_map(void);

/*ʵ���ƶ�*/
void move(void);

/*������ƶ�����ǰλ��*/
void gotoxy(int x, int y);

/*���ع��*/
void HideCursor(void);

char map[31][31] = { 0 };

void open(char *filename) {
FILE *fp = fopen(filename, "r");
if (fp == NULL) {
printf("File open error!");
return;
}
else {
for (int i = 0;i < 31;i++) {
for (int j = 0;j < 31;j++) {
fscanf(fp, "%d", &map[i][j]);
}
}
}
return;
}
void hello(void) {
system("mode con cols=30 lines=15");
system("cls");
printf("*** A LITTLE MAZE ***\n\n\n\n");
printf(" 1.play\n\n");
printf(" 2.quit\n\n\n\n\n");
printf("*** JUST FOR FUN ***\n\n");
HideCursor();
char option;
option = getch();
if (option == '1') {
move();
}
else {
system("cls");
gotoxy(15, 7);
printf("Bye~");
return;
}
}

void show_map(void) {
int i, j;
for (i = 0;i < 31;i++) {
for (j = 0;j < 31;j++) {
if (map[i][j] == 0) printf(" ");
else if (map[i][j] == 1) printf("��");
else printf("��");
}
printf(" \n");
}
}

void move(void) {
system("mode con cols=85 lines=33");
system("cls");

int count = 0;
int x = 29, y = 29;
show_map();

char ch;
do {
ch = getch();
if (ch == -32) {
switch (ch = getch()) {
case 72:ch = 'w';break;
case 80:ch = 's';break;
case 75:ch = 'a';break;
case 77:ch = 'd';break;
default:
printf("Oh!Wrong button!");
break;
}
}
else {
system("cls");
printf("Are you sure you want to quit?\n");
printf(" 1.yes 2.no\n");
if (getch() == '1') {
printf("Bye~");
return;
}
else {
system("cls");
show_map();
}
}
if (ch == 'w'&&map[x - 1][y] == 0) {
map[x][y] = 0;
gotoxy(2 * y, x);
printf(" ");
map[x--][y] = 1;
gotoxy(2 * y, x);
printf("��");
count++;
}
else if (ch == 's'&&map[x + 1][y] == 0) {
map[x][y] = 0;
gotoxy(2 * y, x);
printf(" ");
map[x++][y] = 1;
gotoxy(2 * y, x);
printf("��");
count++;
}
else if (ch == 'a'&&map[x][y - 1] == 0) {
map[x][y] = 0;
gotoxy(2 * y, x);
printf(" ");
map[x][y--] = 1;
gotoxy(2 * y, x);
printf("��");
count++;
}
else if (ch == 'd'&&map[x][y + 1] == 0) {
map[x][y] = 0;
gotoxy(2 * y, x);
printf(" ");
map[x][y++] = 1;
gotoxy(2 * y, x);
printf("��");
count++;
}
if (x == 29 && y == 30) {
system("mode con cols=30 lines=15");
system("cls");
gotoxy(13, 6);
printf("You win!");
return;
}
} while (1);
}

void gotoxy(int x, int y) {
HANDLE hwnd;
COORD coord;
coord.X = x;
coord.Y = y;
hwnd = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hwnd, coord);
HideCursor();
}

void HideCursor(void)//����̵�
{
CONSOLE_CURSOR_INFO cursor_info = { 1, 0 };
SetConsoleCursorInfo(GetStdHandle(STD_OUTPUT_HANDLE), &cursor_info);
}

void refresh(int x, int y) {
for (;y < 31;y++) {
if (map[x][y] == 0)printf(" ");
else if (map[x][y] == 1)printf("%c", 219);
else printf("%c", 236);
}
}
#endif
19 changes: 19 additions & 0 deletions practices/c/level1/p09_maze/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <stdio.h>
/*todolist
1.��ʾ��Ϸ������
2.��ʾ��ͼ
3.��ʾ���λ��
4.��������ƶ�
��
��
��
��
5.���µ�ͼ
6.�˳����ǻ��
6.��ʾ���Ӯ����Ϸ
*/
#include "maze.h"
int main(void) {
open("mazemap.txt");
hello();
}
31 changes: 31 additions & 0 deletions practices/c/level1/p09_maze/mazemap.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1
1 1 1 1 1 0 1 0 1 0 1 0 1 1 1 1 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1
1 0 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 0 1
1 0 1 0 1 1 1 0 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1
1 0 1 0 1 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1
1 0 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1
1 0 1 0 0 0 1 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 0 1
1 0 1 0 0 0 1 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 1
1 0 1 1 1 0 1 1 1 0 1 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