-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathkr.cpp
More file actions
84 lines (82 loc) · 2.71 KB
/
kr.cpp
File metadata and controls
84 lines (82 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/*Ó ôàéë³ çàïèñàí³ êîîðäèíàòè ìàòåð³àëüíèõ òî÷îê íà ïëîùèí³ çàäàí³ ïàðîþ ö³ëèõ ÷èñåë òà
ìàñîþ(ä³éñíå ÷èñëî). Òî÷êè çàïèñóþòüñÿ â ôîðìàò³ : [õ1 , y1, m1 ], [õ2 , y2, m2] , … -
ñàìå òàê ÷åðåç êîìè òà êâàäðàòí³ äóæêè. Çíàéä³òü äâ³ òî÷êè ç íàéá³ëüøèì ðè÷àãîì ñèëè (m*(õ +y)). */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int main() {
FILE* filepoint;
char str[128];
double max_arr[3];
double max = 0;
char* estr;
errno_t err;
err = fopen_s(&filepoint, "test.txt", "r");
if ((err) != 0) {
printf("err");
}
else {
if (filepoint == NULL) { printf("error1\n"); return -1; }
while (1)
{
estr = fgets(str, sizeof(str), filepoint);
if (estr == NULL)
{
if (feof(filepoint) != 0)
{
break;
}
else
{
break;
}
}
printf("%s", str);
for (int i = 0; i < 128; i++) {
if (str[i] == 91) {
double x, y, m;
char temp_x[4];
char temp_y[4];
char temp_m[4];
int j1,j3;
for (int j = i + 1; j < 128; j++) {
if (str[j] == 44) {
j1 = j;
break;
}
temp_x[j - i - 1] = str[j];
}
for (int j2 = j1 + 1; j2 < 128; j2++) {
if (str[j2] == 44) {
j3 = j2;
break;
}
temp_y[j2 - j1 - 1] = str[j2];
}
for (int j4 = j3 + 1; j4 < 128; j4++) {
if (str[j4] == 93) {
break;
}
temp_m[j4 - j3 - 1] = str[j4];
}
char* ptr;
x = strtod(temp_x, &ptr);
y = strtod(temp_y, &ptr);
m = strtod(temp_m, &ptr);
double temp = m * (x + y);
if (temp > max) {
max = temp;
max_arr[0] = x;
max_arr[1] = y;
max_arr[2] = m;
}
}
}
}
printf("\nmax = %lf\n", max);
for (int i = 0; i < 3; i++) {
printf("%lf", max_arr[i]);
}
fclose(filepoint);
}
}