diff --git a/p01/p01.cpp b/p01/p01.cpp new file mode 100644 index 00000000..b0dd3d9b --- /dev/null +++ b/p01/p01.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +using namespace std; +int main() { + HANDLE hOut; + CONSOLE_SCREEN_BUFFER_INFO a; + hOut = GetStdHandle(STD_OUTPUT_HANDLE); + GetConsoleScreenBufferInfo(hOut, &a); + int length_of_console = a.dwSize.X; + int flag = 0; // symbolize whether 'a' has reached the two sides + while(1){ + for(int i=0;i +#include +using namespace std; +bool isPrime(int x){ // simple version + if (x == 1) return false; + for(int i = 2; i * i <= x; i++) if (x % i == 0) return false; + return true; +} +int main() { + int n; + cin >> n; + bool ans = isPrime(n); + if (ans) printf("%d is a prime.\n",n); + else printf("%d is not a prime.\n",n); + system("pause"); + return 0; +} diff --git a/p03_1/p03-1.cpp b/p03_1/p03-1.cpp new file mode 100644 index 00000000..aeb2dac8 --- /dev/null +++ b/p03_1/p03-1.cpp @@ -0,0 +1,14 @@ +#include +using namespace std; +const int lifetime = 84; // His lifetime could be divided by 12 and 7,so by common sense,his lifetime is 84. +const int childhood = 14; +const int youth = 7; +const int bachelor = 12; +const int marriage = 5; +int main() { + int father = childhood + youth + bachelor + marriage; + int son = 0; + int time = lifetime - 4 - father; + if (time == lifetime / 2) cout << 80 << endl; + return 0; +} diff --git a/p03_2/p03-2.cpp b/p03_2/p03-2.cpp new file mode 100644 index 00000000..e3f539f3 --- /dev/null +++ b/p03_2/p03-2.cpp @@ -0,0 +1,22 @@ +#include +using namespace std; +const int max_lifetime = 800; // the life span of the legendary "PengZu" +int main() { + for(int i=0;i +using namespace std; +int digit[5]; // record every digit of the number +int main() { + for(int i = 100;i < 1000;i++){ + int tmp = i; + for(int j = 1;j <= 3;j++){ + digit[j] = tmp % 10; + tmp /= 10; + } + int i0 = digit[1] * digit[1] * digit[1]; + int i1 = digit[2] * digit[2] * digit[2]; + int i2 = digit[3] * digit[3] * digit[3]; + if(i == i0 + i1 + i2) cout << i << endl; + } + return 0; +} diff --git a/p05_1/p05_1.cpp b/p05_1/p05_1.cpp new file mode 100644 index 00000000..0058edb6 --- /dev/null +++ b/p05_1/p05_1.cpp @@ -0,0 +1,20 @@ +#include +#include +using namespace std; +int isPrime(int n){ // ordinary algorithm + if(n == 1) return 0; + for (int i = 2;i * i <= n;i++){ + if (n % i == 0) return 0; + } + return 1; +} +int main() { + int begintime,endtime; + begintime = clock(); + for(int i = 2;i <= 1000;i++){ + if(isPrime(i)) cout << i << ' '; + } + endtime = clock(); + cout << "Runtime is " << endtime - begintime << "ms" << endl; + return 0; +} diff --git a/p05_2/p05_2.cpp b/p05_2/p05_2.cpp new file mode 100644 index 00000000..e9bfeeb1 --- /dev/null +++ b/p05_2/p05_2.cpp @@ -0,0 +1,15 @@ +#include +#include +int main() { + int begintime,endtime; + begintime = clock(); + printf("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 101 103 107 109 113 127 131 137 139 149 151 157 1\n" + "63 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 3\n" + "37 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 5\n" + "21 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 7\n" + "19 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 9\n" + "29 937 941 947 953 967 971 977 983 991 997"); // Apparently this is the most efficient algorithm + endtime = clock(); + printf("Runtime is %dms",endtime - begintime); + return 0; +} diff --git a/p05_3/p05_3.cpp b/p05_3/p05_3.cpp new file mode 100644 index 00000000..d0e3e68d --- /dev/null +++ b/p05_3/p05_3.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +using namespace std; +int main() { // Use"ShaiFa" + int begintime,endtime; + begintime = clock(); + int f[1005]; // identify whether the number is a prime + memset(f,1,sizeof f); + for(int i = 2;i < 1000;i++){ + if(f[i]) + for(int j = 2; j * i <= 1000; j++) f[i*j] = 0; + } + for(int i = 2;i < 1000;i++) if (f[i]) cout << i << ' '; + endtime = clock(); + cout << "Runtime is " << endtime - begintime << "ms" << endl; + return 0; +} diff --git a/p06/p06.cpp b/p06/p06.cpp new file mode 100644 index 00000000..51678910 --- /dev/null +++ b/p06/p06.cpp @@ -0,0 +1,26 @@ +#include +#include +using namespace std; +int isPrime(int x){ + for (int i = 2; i * i <= x; i++){ + if (x % i == 0) return 0; + } + return 1; +} +int main() { + int prime[30]; + int cnt = 0; + for (int n = 2; n < 100; n++){ + if(isPrime(n)) prime[++cnt] = n; + } + for(int x = 4 ; x <= 100; x += 2){ + for(int i = 1; i <= cnt; i++){ + if (isPrime(x - prime[i])){ // could use binary search in prime[] to optimize + printf("%d = %d + %d\n",x,prime[i],x-prime[i]); + break; + } + } + } + system("pause"); + return 0; +} \ No newline at end of file diff --git a/p07/p07.cpp b/p07/p07.cpp new file mode 100644 index 00000000..9bf38274 --- /dev/null +++ b/p07/p07.cpp @@ -0,0 +1,27 @@ +#include +#include +using namespace std; +string a; +char b[1000005]; +void encrypt(string s) { + for (int i = 0; i < s.length(); i++){ + b[i] = s[i] + 3; + cout << b[i]; + } + cout << endl; +} +void decrept(){ + for (int i = 0; i < a.length(); i++){ + char tmp = b[i] - 3; + cout << tmp; + } + cout << endl; +} +int main() { + cin >> a; + encrypt(a); + decrept(); + system("pause"); + return 0; +} + diff --git a/p08/p08.cpp b/p08/p08.cpp new file mode 100644 index 00000000..d8f88c4f --- /dev/null +++ b/p08/p08.cpp @@ -0,0 +1,73 @@ +#include +#include +#include +using namespace std; +int n; +stack a,b,c; + +void output(int n, int x, char a, char b){ + printf("%d : %d from %c to %c\n",n,x,a,b); +} + +char get_top(char x){ + int tmp; + if(x == 'a'){ + tmp = a.top(); + } else if(x == 'b'){ + tmp = b.top(); + } else{ + tmp = c.top(); + } + return tmp; +} + +void reverse(char x, char y){ + int tmp; + if(x == 'a' && y == 'b'){ + tmp = a.top(); + a.pop(); + b.push(tmp); + }else if(x == 'a' && y == 'c'){ + tmp = a.top(); + a.pop(); + c.push(tmp); + }else if(x == 'b' && y == 'a'){ + tmp = b.top(); + b.pop(); + a.push(tmp); + }else if(x == 'b' && y == 'c'){ + tmp = b.top(); + b.pop(); + c.push(tmp); + }else if(x == 'c' && y == 'a'){ + tmp = c.top(); + c.pop(); + a.push(tmp); + }else if(x == 'c' && y == 'b'){ + tmp = c.top(); + c.pop(); + b.push(tmp); + } +} + +void solve(int n, char x, char y, char z){ + if(n == 1){ + output(n,get_top(x),x,z); + reverse(x,z); + return; + } + solve(n-1, x,z,y); + output(n,get_top(x),x,z); + reverse(x,z); + solve(n-1,y,x,z); +} +int main(){ + char x = 'a',y = 'b',z = 'c'; + cin >> n; + for(int i = n; i >= 1; i --){ + a.push(i); + } + solve(n,x,y,z);// + system("pause"); + return 0; +} diff --git a/p09/main.cpp b/p09/main.cpp new file mode 100644 index 00000000..1bb76d2c --- /dev/null +++ b/p09/main.cpp @@ -0,0 +1,204 @@ +#include +#include +#include +#include +#include +#define Wall 1 +#define Road 0 + +#define Start 2 +#define End 3 + +#define Up 1 +#define Down 2 +#define Left 3 +#define Right 4 + +#define n 25 + +int Length, Width; + +typedef struct node{ + int x; + int y; + int c; +} node; +int map[n][n]; +node no[n * n]; + +void move(int x, int y); + +void hidden(); + +void create(int x, int y); + +int get_key(); + +void paint(int x, int y); + +void game(); + +void hidden(){ + HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE); + CONSOLE_CURSOR_INFO c; + GetConsoleCursorInfo(hOut, &c); + c.bVisible = 0; + SetConsoleCursorInfo(hOut, &c); +} + +void move(int x, int y){ + COORD coord; + coord.X = x; + coord.Y = y; + SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); +} + +void create(int x, int y){ + int c[4][2]={0,1,1,0,0,-1,-1,0}; + int i, j, t; + // randomly swap + for(i=0;i<4;i++){ + j=rand()%4; + t=c[i][0];c[i][0]=c[j][0];c[j][0]=t; + t=c[i][1];c[i][1]=c[j][1];c[j][1]=t; + } + map[x][y]=Road; + for(i=0;i<4;i++) + if(map[x + 2 * c[i][0]][y + 2 * c[i][1]]==Wall){ + map[x + c[i][0]][y + c[i][1]]=Road; + create(x+2*c[i][0], y+2*c[i][1]); + } + map[2][1]=Start; + map[Width - 1][Length]=End; +} +int get_key() +{ + char c; + while (c = getch()) + { + c = getch(); + if (c == 72) return Up; // the up key next to '0' + if (c == 80) return Down; + if (c == 75) return Left; + if (c == 77) return Right; + } + return 0; +} + +void paint(int x, int y){ + int i; + move(2 * y + 1, x + 7); + switch (map[x][y]) + { + case Start: + printf("&"); break; + case End: + printf("$"); break; + case Wall: + printf("#"); break; + case Road: + printf("*"); break; + } +} +void game() +{ + int x = 2, y = 1; + int c; + while (1) + { + move(2 * y + 1, x + 7); + printf("@\n"); + if (map[x][y] == End) + { + move(50, 15); + printf("Congratulations!"); + move(2 * y + 1, x + Width - 13); + break; + } + c = get_key(); + switch (c) + { + case Up: + if (map[x - 1][y] != Wall) + { + paint(x, y); + x--; + } + break; + case Down: + if (map[x + 1][y] != Wall) + { + paint(x, y); + x++; + } + break; + case Left: + if (map[x][y - 1] != Wall) + { + paint(x, y); + y--; + } + break; + case Right: + if (map[x][y + 1] != Wall) + { + paint(x, y); + y++; + } + break; + } + } +} + +int main() +{ + system("COLOR 00"); + int i, j, s; + printf("Start:1 End:2 Please confirm your purpose\n"); + printf("Input:"); + scanf("%d", &s); + switch (s) + { + case 1: + printf("Input the width of maze(Odd): "); + scanf("%d", &Width); + printf("Input the length of maze(Odd): "); + scanf("%d", &Length); + printf(" "); + for (i = 65; i <= (Length + 64); i++) + printf("%c ", i); + printf("\n"); + for (i = 65; i <= (Length + 64); i++) + printf(" %c\n", i); + system("COLOR 56"); + srand((unsigned)time(NULL)); + hidden(); + for (i = 0; i <= Length + 1; i++) + for (j = 0; j <= Width + 1; j++) + if (i == 0 || i == Length + 1 || j == 0 || j == Width + 1) + map[i][j] = Road; + else map[i][j] = Wall; + create(2 * (rand() % (Length / 2) + 1), 2 * (rand() % (Width / 2) + 1)); + for (i = 0; i <= Length + 1; i++) + { + map[i][0] = Wall; + map[i][Width + 1] = Wall; + } + for (j = 0; j <= Width + 1; j++) + { + map[0][j] = Wall; + map[Length + 1][j] = Wall; + } + for (i = 1; i <= Length; i++) + for (j = 1; j <= Width; j++) + paint(i, j); + game(); + getch(); + return 0; + break; + case 2: + printf("Goodbye~"); + break; + default: break; + } +} \ No newline at end of file diff --git a/p10/main.cpp b/p10/main.cpp new file mode 100644 index 00000000..8b2f19ff --- /dev/null +++ b/p10/main.cpp @@ -0,0 +1,325 @@ +#include +#include +#include +#include +using namespace std; +void DisplayMap(); +const int completelevel = 3; +int Map[20][20]; +int level = 0; +int x,y; +int dataMap[30][20][20]; +int bestdata[30] = {0}; +int ReadKey() +{ + int a; + a = getch(); + if(a == 114) + return 0; + if(a == 122) + return 10; + if(a == 120) + return 11; + if(a == 224) + { + a = getch(); + switch(a) + { + case 72:return 1; + case 75:return 2; + case 80:return 3; + case 77:return 4; + } + } + else + return 0; +} +void FindXY() +{ + int i,j; + for(i = 0;i<20;i++) + for(j = 0;j<20;j++) + if(Map[i][j] == 5 || Map[i][j] == 7) + { + y = i;x = j;break; + } +} +void GameStart() +{ + int i,j; + for(i = 0;i<20;i++) + for(j = 0;j<20;j++) + Map[i][j] = dataMap[level][i][j]; + FindXY(); + DisplayMap(); + printf("第 %d 关\t\t最佳纪录 %d 步\n\nR:重玩\tZ:上关\tX:下关\n",level+1,bestdata[level]); +} +void HandleKey(int key) +{ + if(key == 1) + { + int y1,y2; + y1 = y-1; + y2 = y-2; + if(y1<0) + return; + else if(Map[y1][x] == 3||Map[y1][x] == 4) + { + if(Map[y2][x] == 3 ||Map[y2][x] == 4||Map[y2][x] == 1) + return; + else if(Map[y2][x] == 0 ||Map[y2][x] == 2) + { + Map[y][x] -= 5; + if(Map[y1][x] == 3) + Map[y1][x] = 5; + else if(Map[y1][x] == 4) + Map[y1][x] = 7; + if(Map[y2][x] == 0) + Map[y2][x] = 3; + else if(Map[y2][x] == 2) + Map[y2][x] = 4; + FindXY(); + + } + + } + else if(Map[y1][x] == 0 ||Map[y1][x] == 2) + { + + Map[y][x] -= 5;Map[y1][x] += 5; + FindXY(); + + } + + } + else if(key == 2) //左 + { + int x1,x2; + x1 = x-1; + x2 = x-2; + if(x1<0) + return ; + else if(Map[y][x1] == 1) + return ; + else if(Map[y][x1] == 3||Map[y][x1] == 4) + { + if(Map[y][x2] == 3 ||Map[y][x2] == 4||Map[y][x2] == 1) + return ; + else if(Map[y][x2] == 0 ||Map[y][x2] == 2) + { + Map[y][x] -= 5; + if(Map[y][x1] == 3) + Map[y][x1] = 5; + else if(Map[y][x1] == 4) + Map[y][x1] = 7; + if(Map[y][x2] == 0) + Map[y][x2] = 3; + else if(Map[y][x2] == 2) + Map[y][x2] = 4; + FindXY(); + + } + + } + else if(Map[y][x1] == 0 ||Map[y][x1] == 2) + { + + Map[y][x] -= 5;Map[y][x1] += 5; + FindXY(); + + } + + } + else if(key == 3)//下 + { + int y1,y2; + y1 = y+1; + y2 = y+2; + if(y1 >= 20) + return ; + else if(Map[y1][x] == 3||Map[y1][x] == 4) + { + if(Map[y2][x] == 3 ||Map[y2][x] == 4||Map[y2][x] == 1) + return ; + else if(Map[y2][x] == 0 ||Map[y2][x] == 2) + { + Map[y][x] -= 5; + if(Map[y1][x] == 3) + Map[y1][x] = 5; + else if(Map[y1][x] == 4) + Map[y1][x] = 7; + if(Map[y2][x] == 0) + Map[y2][x] = 3; + else if(Map[y2][x] == 2) + Map[y2][x] = 4; + FindXY(); + + } + + } + else if(Map[y1][x] == 0 ||Map[y1][x] == 2) + { + + Map[y][x] -= 5;Map[y1][x] += 5; + FindXY(); + + } + + } + else if(key == 4)//右 + { + int x1,x2; + x1 = x+1; + x2 = x+2; + if(x1 >= 20) + return ; + else if(Map[y][x1] == 1) + return ; + else if(Map[y][x1] == 3||Map[y][x1] == 4) + { + if(Map[y][x2] == 3 ||Map[y][x2] == 4||Map[y][x2] == 1) + return ; + else if(Map[y][x2] == 0 ||Map[y][x2] == 2) + { + Map[y][x] -= 5; + if(Map[y][x1] == 3) + Map[y][x1] = 5; + else if(Map[y][x1] == 4) + Map[y][x1] = 7; + if(Map[y][x2] == 0) + Map[y][x2] = 3; + else if(Map[y][x2] == 2) + Map[y][x2] = 4; + FindXY(); + } + } + else if(Map[y][x1] == 0 ||Map[y][x1] == 2) + { + + Map[y][x] -= 5;Map[y][x1] += 5; + FindXY(); + + } + } +} +void DisplayMap() +{ + int i,j; + for(i = 0;i<20;i++) + { + for(j = 0;j<20;j++) + { + switch(Map[i][j]) + { + case 0:printf(" ");break; + case 1:printf("▓");break; + case 2:printf("※");break; + case 3:printf("□");break; + case 4:printf("■");break; + case 5:printf("♀");break; + case 7:printf("♂");break; + } + } + printf("\n"); + } + +} +int JudgeComplete() +{ + int i,j; + for(i = 0;i < 20; i++) + for(j = 0;j < 20; j++) + if(2 == Map[i][j]||3 == Map[i][j]) return 0; + return 1; +} + +void OpenData() +{ + int data; + FILE *fp; + if(level == 0) fp=fopen("C:\\Users\\john\\Desktop\\P10\\map1.txt","r"); + else if(level == 1) fp=fopen("C:\\Users\\john\\Desktop\\P10\\map2.txt","r"); + else if(level == 2) fp=fopen("C:\\Users\\john\\Desktop\\P10\\map3.txt","r"); + if(!fp) + { + printf("can't open file\n"); + } + while(!feof(fp)) + { + for(int i = 0; i < 20 ; i++) + for (int j = 0; j < 20; j++) + fscanf(fp,"%d",&dataMap[level][i][j]); + printf("%4d",data); + } + printf("\n"); + fclose(fp); + return; +} + +void SaveData() +{ + ofstream ofile("C:\\Users\\john\\Desktop\\P10\\save.txt",ios::binary); + if(!ofile) + { + printf("不能存入文件\n"); + return; + } + for(int i = 0;i +#include +using namespace std; + +struct node{ + int data; + struct node* next = NULL; +}; +typedef struct node node; + +node* init(){ + node* head = (node*) malloc(sizeof(node)); + head -> next = NULL; + return head; +} + +node* find_tail(node* head){ + while(head -> next != NULL) head = head -> next; + return head; +} + +void add(node* head, int x){ // add a node whose data is x + node* p = (node*) malloc(sizeof(node)); + p->data = x; + p->next = NULL; + node *tail = find_tail(head); + tail->next = p; +} + +int find_value_value(node* head, int x){ + int cnt = 0; + bool found = 0; + while(head -> next != NULL && head -> data != x){ + head = head -> next; + cnt++; + } + if(head -> data == x) found = 1; + return found ? cnt : -1; +} + +node* find_value_pointer(node* head, int x){ + while(head != NULL && head -> data != x){ + head = head -> next; + } + return head; +} + +void walk(node* head){ + while(head -> next != NULL){ + cout << head -> next -> data << ' ' ; + head = head -> next; + } +} + +node* find_father(node* head,node* x){ + while(head != NULL){ + if(head -> next == x){ + return head; + } else head = head -> next; + } + return NULL; +} + +node* reverse(node* head){//headʼ + node* prev = NULL; + node* current = head; + while (current) { + node* n = current->next; + current->next = prev; + prev = current; + current = n; + } + return prev; +} + +int main() { + node* h = init(); + add(h,1); + add(h,2); + add(h,5); + add(h,1564); + add(h,156); + add(h,15); + add(h,5); + walk(h); + cout << endl; + cout << find_value_value(h,5) << endl; + node* h1 = find_value_pointer(h,5); + cout << find_value_value(h,5) + find_value_value(h1->next,5) + 1 << endl; + cout << endl; + + system("pause"); + return 0; +} + diff --git a/p12/main.cpp b/p12/main.cpp new file mode 100644 index 00000000..d7555eda --- /dev/null +++ b/p12/main.cpp @@ -0,0 +1,132 @@ +#include +#include +#include +#include +const int M = 10000; + +int N,P; // 表示当前数量与总数量 + +typedef struct{ + int num; //货品编号 + char name[30]; //货品名称 + int stock; //原始库存 + int in; //入库数目 + int out; //出库数目 + int amount; //最终库存 +} goods; + +goods g[M]; //用于存放货品信息 +goods in[M]; //用于存放入库货品信息 +goods out[M]; //用于存放出库货品信息 + +void read(); //读取货品信息 + +void add(); + +void off(); + +void display(); + +int write(); + +int main(){ + int op = 1; + read(); + while(op){ + system("cls"); + printf("\n\n"); + printf("*********************************************\n"); + printf("* *\n"); + printf("* 1.add 2.off *\n"); + printf("* *\n"); + printf("* 3.display 4.exit *\n"); + printf("* *\n"); + printf("*********************************************\n"); + printf("Select the function you need:"); + scanf("%d",&op); + switch(op){ + case 1:add(); display();break; + case 2:off(); display();break; + case 3:display(); break; + case 4:op = 0; break; + } + printf("\n\nPress any key to continue...\n"); + } + write(); + system("pause"); + return 0; +} + +void read(){ + FILE* fp; + N = 0; + fp = fopen("C:\\Users\\john\\CLionProjects\\p12\\goods.txt","r"); + while(fscanf(fp,"%d%s", &g[N].num, &g[N].name) != EOF) + N ++; + fclose(fp); + P = N; +} + +void add(){ //读入入库文件 + FILE* fp; + int i,j; + N = 0; + fp = fopen("C:\\Users\\john\\CLionProjects\\p12\\stock.txt","r"); + while(fscanf(fp,"%d%d",&in[N].num, &in[N].in) != EOF) + N++; + fclose(fp); + for(i = 0;i < P;i++){ + for(j = 0;j < N;j++){ + if(in[i].num == g[j].num) + g[j].in = in[j].in; + } + } + for(i = 0;i < P;i++) + g[i].amount = g[i].stock + g[i].in; +} + +void off(){ //读入出库文件 + FILE* fp; + int i,j; + N=0; + fp = fopen("C:\\Users\\john\\CLionProjects\\p12\\stockout.txt","r"); + while(fscanf(fp,"%d%d", &out[N].num, &out[N].out) != EOF) + N++; + fclose(fp); + for(i = 0;i < P; i++){ + for(j = 0;j < N; j++){ + if(out[i].num == g[j].num) + g[j].out = out[j].out; + } + } + for(i = 0; i < P; i++) + g[i].amount = g[i].stock + g[i].in - g[i].out; +} + +void display(){ //显示库存情况 + int i,j; + system("cls"); + printf("num name stock add off final\n"); + for(i = 0,j = 1;i < P; i++, j++){ + HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE); + SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED); + printf("%-9d %-10s%-10d%-10d%-10d%-10d\n", g[i].num, g[i].name, g[i].stock, g[i].in, g[i].out, g[i].amount); + if(j % 10 == 0 && j != P){ //每次显示十行 + printf("Press any key to continue..."); + getch(); + puts("\n"); + SetConsoleTextAttribute(handle, FOREGROUND_INTENSITY | FOREGROUND_RED| FOREGROUND_GREEN | FOREGROUND_BLUE); + printf("num name add off final\n"); + } + } +} + +int write(){ + FILE* fp; + int i; + fp = fopen("C:\\Users\\john\\CLionProjects\\p12\\amount.txt","w"); + for(i = 0; i < P; i++) + fprintf(fp,"%d %s %d %d %d %d\n",g[i].num,g[i].name,g[i].stock,g[i].in,g[i].out,g[i].amount); + fclose(fp); + return 1; +}