-
Notifications
You must be signed in to change notification settings - Fork 35
yutao #49
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
base: master
Are you sure you want to change the base?
yutao #49
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| #include <iostream> | ||
| using namespace std; | ||
| typedef int Data_type; | ||
|
|
||
| struct Linked_list | ||
| { | ||
| Data_type data; | ||
| Linked_list * next; | ||
| }; | ||
|
|
||
| class Queue | ||
| { | ||
| public: | ||
| Queue() : head(0),tail(0),num(0) {} | ||
| void append (Data_type date); | ||
| Data_type pop(); | ||
| bool is_full() { return num >= Max_num; } | ||
| bool is_empty() { return num <= 0; } | ||
| private: | ||
| enum { Max_num = 100 }; | ||
| Linked_list *head,*tail; | ||
| int num; | ||
| }; | ||
|
|
||
|
|
||
| void Queue::append(Data_type data) | ||
| { | ||
| if(is_full()) | ||
| { | ||
| cerr << "Fail to append, Queue is full!\n"; | ||
| return; | ||
| } | ||
| if(is_empty()) | ||
| { | ||
| head = tail = new Linked_list; | ||
| } | ||
| else | ||
| { | ||
| tail = tail->next = new Linked_list; | ||
| } | ||
| tail->data = data; | ||
| tail->next = 0; | ||
| num++; | ||
| } | ||
|
|
||
| Data_type Queue::pop() | ||
| { | ||
| if(is_empty()) | ||
| { | ||
| cerr << "Fail to pop, Queue is empty!\n"; | ||
| return -1; | ||
| } | ||
| Data_type data = head->data; | ||
| Linked_list *tmp = head; | ||
| head = head->next; | ||
| delete tmp; | ||
| num--; | ||
| return data; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| int main() | ||
| { | ||
| Queue q; | ||
| q.append(1); | ||
| q.append(2); | ||
| q.append(3); | ||
| int data = q.pop(); | ||
| cout << noskipws << data << endl; | ||
| data = q.pop(); | ||
| cout << noskipws << data << endl; | ||
| data = q.pop(); | ||
| cout << noskipws << data << endl; | ||
| data = q.pop(); | ||
| cout << noskipws << data << endl; | ||
|
|
||
| for(int i = 0; i < 100; i++) | ||
| { | ||
| q.append(i); | ||
| } | ||
| q.append(1); | ||
| q.append(1); | ||
| return 0; | ||
| } | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| #include <iostream> | ||
| using namespace std; | ||
| typedef int Data_type; | ||
| class Stack | ||
| { | ||
| public: | ||
| Stack() : i(-1) {} | ||
| void push(Data_type data) | ||
| { | ||
| if(is_full()) | ||
| { | ||
| cerr << "Fail to push, Stack is full!\n"; | ||
| return; | ||
| } | ||
| arr[++i] = data; | ||
| } | ||
| Data_type pop() | ||
| { | ||
| if(is_empty()) | ||
| { | ||
| cerr << "Fail to pop, Stack is empty\n"; | ||
| return (-1); | ||
| } | ||
| return arr[i--]; | ||
| } | ||
| bool is_full() { return (i >= Size - 1); } | ||
| bool is_empty() { return (i < 0); } | ||
| private: | ||
| enum { Size = 100 }; | ||
| int i; | ||
| Data_type arr[Size]; | ||
| }; | ||
|
|
||
|
|
||
| int main() | ||
| { | ||
|
|
||
| Stack s; | ||
| s.push(1); | ||
| s.push(2); | ||
| s.push(3); | ||
| int data = s.pop(); | ||
| cout << noskipws << data << endl; | ||
| data = s.pop(); | ||
| cout << noskipws << data << endl; | ||
| data = s.pop(); | ||
| cout << noskipws << data << endl; | ||
| data = s.pop(); | ||
| cout << noskipws << data << endl; | ||
|
|
||
| for(int i = 0; i < 100; i++) | ||
| { | ||
| s.push(i); | ||
| } | ||
| s.push(1); | ||
| s.push(1); | ||
| return 0; | ||
| } | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| #include <stdio.h> | ||
| #include <unistd.h> | ||
| #define COLUMN 80 | ||
|
|
||
| int main(){ | ||
| int blank,location; | ||
|
|
||
| for (location = 1; location <=COLUMN ; location++){ | ||
| for (blank=1; blank < location; blank++){ | ||
| printf(" "); | ||
| } | ||
| putchar('A'); | ||
| usleep(2000000); | ||
| system("clear"); | ||
| } | ||
| for (location = location-1; location >=1; location--){ | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 闻到了重复的味道,请消除之 |
||
| for (blank=1; blank < location; blank++){ | ||
| printf(" "); | ||
| } | ||
| putchar('A'); | ||
| usleep(200000); | ||
| system("clear"); | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #include <stdio.h> | ||
|
|
||
| int main() | ||
| { | ||
| int x; | ||
| for(x=1; x<150; x++){ | ||
| if(x/6 + x/12 + x/7 + 5 + x/2 + 4 ==x) | ||
| break; | ||
| } | ||
| printf("The father had lived for %d years.\n",x); | ||
| return 0; | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <math.h> | ||
|
|
||
| int isPrime(int x) | ||
| { | ||
| int i; | ||
| int dlm = sqrt((double)x); | ||
|
|
||
| for (i=2; i<=dlm; i++) | ||
| { if (x%i==0) break; } | ||
| if (x==1) return 0; | ||
| else if (x==2 || x==3 || i>dlm) | ||
| { return 1; } | ||
| else return 0; | ||
| return 0; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| int i,j; | ||
|
|
||
| for (i=4; i<=100; i=i+2) | ||
| { for (j=2; j<=i/2; j++) | ||
| { if (isPrime(j) && isPrime(i-j)) | ||
| { printf("\n%d = prime%d + prime%d.",i,j,i-j); | ||
| break; } } } | ||
| return 0; | ||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| #include <stdio.h> | ||
| #include <math.h> | ||
| #include <time.h> | ||
|
|
||
| int main() | ||
| { | ||
| int i,j; | ||
| long begin,end; | ||
|
|
||
| begin = time(NULL); | ||
| printf("\nThe primes are:\n%-7d",2); | ||
| for (i=3; i<1000; i=i+2){ | ||
| for (j=3; j<=(int)sqrt(i); j=j+2) | ||
| if (i%j == 0) break; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 加大括号 |
||
| if (j > (int)sqrt(i) ) printf("%-7d",i); | ||
| } | ||
| end = time(NULL); | ||
| printf("\nThe begin time is: %d.",begin); | ||
| printf("\nThe end time is: %d.",end); | ||
| printf("\nThe total time is: %lf seconds.",(end-begin)/1000000.0); | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| void( | ||
|
|
||
| int mian() | ||
| { | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include <stdio.h> | ||
| #include <math.h> | ||
|
|
||
| int main() | ||
| { | ||
| int i,num; | ||
|
|
||
| printf("\nPlease enter a number: "); | ||
| scanf("%d",&num); | ||
| if (num == 2) | ||
| printf("\nIt's a prime.\n"); | ||
| else{ | ||
| for (i=2; i<=sqrt(num); i=i+2){ | ||
| if (num % i==0){ | ||
| printf("\nIt's not a prime.\n"); | ||
| break; | ||
| } | ||
| } | ||
| if (i > sqrt(num)) | ||
| printf("\nIt's a prime.\n"); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 大括号 |
||
| } | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| #include <stdio.h> | ||
|
|
||
| int main() | ||
| { | ||
| int i,ones,tens,hundreds; | ||
| for (i=100; i<1000; i++){ | ||
| ones = i % 10; | ||
| tens = i/10 %10; | ||
| hundreds = i/100; | ||
| if (ones*ones*ones + tens*tens*tens + hundreds*hundreds*hundreds == i) | ||
| printf("%7d\n",i); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 大括号 |
||
| } | ||
| return 0; | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include <stdio.h> | ||
| #include <unistd.h> | ||
| #define COLUMN 80 | ||
| #define PAUSE 100000 | ||
|
|
||
| int main(){ | ||
| int blank,location=1,back=0; | ||
|
|
||
| do | ||
| { for (blank=1; blank<location; blank++) | ||
| { printf(" "); } | ||
| puts("A"); | ||
| usleep(PAUSE); | ||
| system("clear"); | ||
| if (location==COLUMN) back=1; | ||
| if (!back) location++; | ||
| else location--; | ||
| } | ||
| while (location<=COLUMN && location>=1); | ||
|
|
||
| return 0; | ||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| #include <stdio.h> | ||
| #include <stdlib.h> | ||
| #include <math.h> | ||
|
|
||
| int isPrime(int x) | ||
| { | ||
| int i; | ||
| int dlm = sqrt((double)x); | ||
|
|
||
| for (i=2; i<=dlm; i++) | ||
| { if (x%i==0) break; } | ||
| if (x==1) return 0; | ||
| else if (x==2 || x==3 || i>dlm) | ||
| { return 1; } | ||
| else return 0; | ||
| return 0; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| int i,j; | ||
|
|
||
| for (i=4; i<=100; i=i+2) | ||
| { for (j=2; j<=i/2; j++) | ||
| { if (isPrime(j) && isPrime(i-j)) | ||
| { printf("\n%d = prime%d + prime%d.",i,j,i-j); | ||
| break; } } } | ||
| return 0; | ||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
定义常量