Skip to content

Commit

Permalink
[IM]: c++学习代码
Browse files Browse the repository at this point in the history
  • Loading branch information
guziqiu committed Jun 28, 2022
1 parent 4f34e3a commit 1e0a9c4
Show file tree
Hide file tree
Showing 1,885 changed files with 437,614 additions and 0 deletions.
18 changes: 18 additions & 0 deletions 03.code/00.c/00.test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*************************************************************************
> File Name: test.c
> Author: Apricity
> Mail: [email protected]
> Created Time: Tue 24 Nov 2020 06:57:27 PM CST
************************************************************************/

#include<stdio.h>
int main(int argc,const char* argv[]){
int n;
int res;
while(res = scanf("%d", &n) != EOF){
getchar();
printf(" has %d digits! res = %d \n",printf("%d",n),res);
}

return 0;
}
20 changes: 20 additions & 0 deletions 03.code/00.c/00.test2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*************************************************************************
> File Name: test2.c
> Author: Apricity
> Mail: [email protected]
> Created Time: Tue 24 Nov 2020 07:28:46 PM CST
************************************************************************/

#include<stdio.h>
#include<string.h>
int main(int argc,const char* argv[]){

char str[1000] = {0};
int i;
while(scanf("%[^\n]s",str) != EOF){
getchar();
printf(" has %d digits!\n", printf("%s", str));
printf("%s has %ld digits!\n", str, strlen(str));
}
return 0;
}
26 changes: 26 additions & 0 deletions 03.code/00.c/01.阶乘.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*************************************************************************
> File Name: 1.阶乘.c
> Author: Apricity
> Mail:
> Created Time: Tue 01 Dec 2020 07:22:02 PM CST
************************************************************************/

#include<stdio.h>

int fac(int i){
#if 1
if(i > 1){
return i * fac(i - 1);
}
return 1;
#endif
// i > 1 ? (return i * fac(i - 1)):(return 1);
}


int main(int argc,const char* argv[]){
int n;
scanf("%d", &n);
printf("%d\n", fac(n));
return 0;
}
57 changes: 57 additions & 0 deletions 03.code/00.c/02.EP45.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*************************************************************************
> File Name: 2.EP45.c
> Author: Apricity
> Mail:
> Created Time: Tue 01 Dec 2020 08:45:37 PM CST
************************************************************************/

#include<stdio.h>
int Triangle(int n){
return n * n(n + 1) / 2;
}
int Pentagonal(int n){
return n * (3 * n - 1) /2;
}
int Hexagonal(int n){
return n * (2 * n - 1);
}
int binary_search(int (*num)(int), int n, int x){
int head = 0;
int tail = n - 1;
int mid;
while (head <= tail) {
mid = (head + tail) >> 1;
if(num(mid) == x) return mid;
if(num(mid) < x) head = mid + 1;
else tail = mid - 1;
}
return -1;
}

int main(int argc,const char* argv[]){
int n=285;
while (1) {
n++;
int val = Triangle(n);
if (binary_search(Pentagonal, val, val) == -1) continue;
if(binary_search(Hexagonal, val ,val) != -1) continue;

printf("%d\n", val);
}
return 0;
}















25 changes: 25 additions & 0 deletions 03.code/00.c/03.printf.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*************************************************************************
> File Name: 3.printf.c
> Author: Apricity
> Mail: [email protected]
> Created Time: Tue 24 Nov 2020 08:36:52 PM CST
************************************************************************/

#include<stdio.h>
int main(int argc,const char* argv[]){
int n;
char str[1000] = {0};
# if 0
//标准输入
scanf("%d", &n);//stdin
//标准输出
printf("%d\n", n);//stdout stderr
# endif
sprintf(str, "%d.%d.%d.%d", 192, 168, 1, 1);
printf("str = %s\n", str);
FILE *fout = fopen("output", "w");

fprintf(stdout, "stdout = %s\n", str);
fprintf(stderr, "stdoerr = %s", str);
return 0;
}
12 changes: 12 additions & 0 deletions 03.code/00.c/04.apow.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*************************************************************************
> File Name: apow.c
> Author: Apricity
> Mail:
> Created Time: Thu 26 Nov 2020 07:41:53 PM CST
************************************************************************/

#include<stdio.h>
int main(int argc,const char* argv[]){

return 0;
}
15 changes: 15 additions & 0 deletions 03.code/00.c/04.pow3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*************************************************************************
> File Name: pow.c
> Author: Apricity
> Mail:
> Created Time: Thu 26 Nov 2020 07:30:44 PM CST
************************************************************************/

#include<stdio.h>
#include<math.h>
int main(int argc,const char* argv[]){
double n;
scanf("%lf", &n);
printf("%f", pow(n, 1.0 / 3));
return 0;
}
27 changes: 27 additions & 0 deletions 03.code/00.c/05.good.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*************************************************************************
> File Name: good.c
> Author: Apricity
> Mail:
> Created Time: Sat 28 Nov 2020 02:38:36 PM CST
************************************************************************/

#include<stdio.h>
int main(int argc,const char* argv[]){
int n;
while(~scanf("%d", &n)){
if (!n) {
printf("FOOLISH\n");
} else if (n < 60){
printf("FALL\n");
} else if (n < 75){
printf("MEDIUM\n");
} else {
printf("GOOD\n");
}
n == 0?(printf("FOOLISH1\n")):(n < 60?(printf("FALL1\n")):( n < 75?(printf("MEDIUM\n")):(printf("GOOD\n")) ));
}



return 0;
}
25 changes: 25 additions & 0 deletions 03.code/00.c/06.switch1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*************************************************************************
> File Name: switch1.c
> Author: Apricity
> Mail:
> Created Time: Sat 28 Nov 2020 03:19:45 PM CST
************************************************************************/

#include<stdio.h>
int main(int argc,const char* argv[]){
int n;
scanf("%d", &n);
switch(n){
case 1:
printf("one ");
case 2:
printf("two ");
case 3:
printf("three\n");
break;
default:
printf("error\n");
break;
}
return 0;
}
20 changes: 20 additions & 0 deletions 03.code/00.c/07.while1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*************************************************************************
> File Name: while1.c
> Author: Apricity
> Mail:
> Created Time: Sat 28 Nov 2020 04:29:31 PM CST
************************************************************************/

#include<stdio.h>
int main(int argc,const char* argv[]){
int n;
n = 1;
while (n <= 100) {
printf("%d\n", n);
n++;
}
for (int i = 1; i <= 100; i++){
printf("%d\n", i);
}
return 0;
}
22 changes: 22 additions & 0 deletions 03.code/00.c/09.gcd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*************************************************************************
> File Name: 9.gcd.c
> Author: Apricity
> Mail:
> Created Time: Thu 03 Dec 2020 07:23:41 PM CST
************************************************************************/

#include<stdio.h>
int gcd(int a, int b) {
// if (b == 0) return a;
// if (!b) return a;
// return gcd(b, a % b);
return (b ? gcd(b, a % b) : a);
}

int main(int argc,const char* argv[]){
int a, b;
while(~scanf("%d%d", &a, &b)) {
printf("gcd(%d, %d) = %d\n", a, b, gcd(a, b));
}
return 0;
}
44 changes: 44 additions & 0 deletions 03.code/00.c/10.EP45.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*************************************************************************
> File Name: 10.EP45.c
> Author: Apricity
> Mail:
> Created Time: Sat 05 Dec 2020 07:53:48 AM CST
************************************************************************/

#include<stdio.h>
typedef long long int1;
int1 Triangle(int1 n){
return n * (n + 1) / 2;
}
int1 Pentagonal(int1 n){
return n * (3 * n - 1) /2;
}
int1 Hexagonal(int1 n){
return n * (2 * n - 1);
}
int1 binary_search(int1 (*num)(int1), int1 n, int1 x) {
int1 head = 0;
int1 tail = n - 1;
int1 mid;
while (head <= tail) {
if (mid < 0) printf("error\n");
mid = (head + tail) / 2;
if (num(mid) == x) return mid;
if (num(mid) < x) head = mid + 1;
else tail = mid - 1;
}
return -1;
}
int main(int argc,const char* argv[]){
int1 n = 285;
while (1) {
n++;
int1 temp = Triangle(n);
if (binary_search(Pentagonal, temp, temp) == -1) continue;
if (binary_search(Hexagonal, temp, temp) != -1) continue;
printf("%lld\n", temp);
break;

}
return 0;
}
15 changes: 15 additions & 0 deletions 03.code/00.c/10.array(1).c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*************************************************************************
> File Name: 10.array.c
> Author: Apricity
> Mail:
> Created Time: Sat 05 Dec 2020 06:33:53 PM CST
************************************************************************/

#include<stdio.h>
int main(int argc,const char* argv[]){
int arry[100] = {0};
for (int i = 1; i <= 100; i++) {
printf("array[%d] = %d\n", i - 1, arry[i - 1]);
}
return 0;
}
15 changes: 15 additions & 0 deletions 03.code/00.c/10.array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*************************************************************************
> File Name: 10.array.c
> Author: Apricity
> Mail:
> Created Time: Sat 05 Dec 2020 06:33:53 PM CST
************************************************************************/

#include<stdio.h>
int main(int argc,const char* argv[]){
int arry[100] = {0};
for (int i = 1; i <= 100; i++) {
printf("array[%d] = %d\n", i - 1, arry[i - 1]);
}
return 0;
}
27 changes: 27 additions & 0 deletions 03.code/00.c/11.prime.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*************************************************************************
> File Name: 11.prime.c
> Author: Apricity
> Mail:
> Created Time: Sat 05 Dec 2020 07:28:24 PM CST
************************************************************************/

#include<stdio.h>
#define max_n 100

int prime[max_n + 5] = {0};
void init() {
for (int i = 2; i <= max_n; i++) {
if (prime[i]) continue;
prime[++prime[0]] = i;
for (int j = i * i; j <= max_n; j += i) {
prime[j] = 1;
}
}
}
int main(int argc,const char* argv[]){
init();
for (int i = 2; i <= prime[0]; i++){
printf("%d\n", prime[i]);
}
return 0;
}
Loading

0 comments on commit 1e0a9c4

Please sign in to comment.