Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
PPC2025_CT11
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Kazuyuki Omi
PPC2025_CT11
Commits
df248826
Commit
df248826
authored
3 days ago
by
Kazuyuki Omi
Browse files
Options
Downloads
Patches
Plain Diff
minor changes in config section
parent
d77ffb48
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
hw/hw01/main
+0
-0
0 additions, 0 deletions
hw/hw01/main
hw/hw01/main.cpp
+57
-67
57 additions, 67 deletions
hw/hw01/main.cpp
with
57 additions
and
67 deletions
hw/hw01/main
+
0
−
0
View file @
df248826
No preview for this file type
This diff is collapsed.
Click to expand it.
hw/hw01/main.cpp
+
57
−
67
View file @
df248826
...
...
@@ -19,34 +19,33 @@ typedef struct setting
int
zaloha
=
0
;
}
setting
;
int
get_error_100
(
setting
&
a
)
int
get_error_100
(
setting
&
a
)
{
std
::
cout
<<
"Out of Range"
<<
std
::
endl
;
exit
(
100
);
exit
(
100
);
}
int
get_error_101
(
setting
&
a
)
int
get_error_101
(
setting
&
a
)
{
std
::
cerr
<<
"Invalid input"
<<
std
::
endl
;
std
::
cerr
<<
"Invalid input"
<<
std
::
endl
;
exit
(
101
);
}
void
get_error_102
(
setting
&
a
)
void
get_error_102
(
setting
&
a
)
{
std
::
cerr
<<
"Invalid configration"
<<
std
::
endl
;
exit
(
102
);
std
::
cerr
<<
"Invalid configration"
<<
std
::
endl
;
exit
(
102
);
}
void
get_config
(
setting
&
a
)
{
std
::
string
line
;
std
::
cout
<<
"start configration"
<<
std
::
endl
;
std
::
getline
(
std
::
cin
,
line
);
std
::
istringstream
iss
(
line
);
std
::
string
setting
;
while
(
iss
>>
setting
)
{
std
::
istringstream
setting_stream
(
setting
);
while
(
std
::
getline
(
std
::
cin
,
line
))
{
if
(
line
==
"="
)
break
;
std
::
istringstream
setting_stream
(
line
);
std
::
string
key
;
std
::
getline
(
setting_stream
,
key
,
'='
);
...
...
@@ -57,14 +56,12 @@ void get_config(setting &a)
else
if
(
key
==
"config.max"
)
{
setting_stream
>>
a
.
max
;
if
(
a
.
min
>
a
.
max
)
get_error_102
(
a
);
if
(
a
.
min
>
a
.
max
)
get_error_102
(
a
);
}
else
if
(
key
==
"config.width"
)
{
setting_stream
>>
a
.
width
;
if
(
a
.
width
<
0
)
get_error_102
(
a
);
if
(
a
.
width
<
0
)
get_error_102
(
a
);
}
else
if
(
key
==
"config.align"
)
{
...
...
@@ -76,7 +73,7 @@ void get_config(setting &a)
}
else
if
(
key
==
"config.header"
)
{
setting_stream
>>
a
.
header
;
setting_stream
>>
a
.
header
;
}
}
}
...
...
@@ -85,9 +82,7 @@ int get_sum(std::vector<int> numbers, int range)
{
int
suma
=
0
;
for
(
int
i
=
0
;
i
<
range
;
i
++
)
{
suma
+=
numbers
[
i
];
}
return
suma
;
}
...
...
@@ -99,7 +94,7 @@ int check_num_of_lettersb4(setting &a, const int &value)
std
::
cerr
<<
"Cell is too short"
<<
std
::
endl
;
exit
(
103
);
}
else
if
(
tmp_length
>
a
.
width
&&
a
.
stretch
==
1
)
else
if
(
tmp_length
>
a
.
width
&&
a
.
stretch
==
1
)
{
a
.
zaloha
+=
tmp_length
-
a
.
width
;
}
...
...
@@ -107,11 +102,10 @@ int check_num_of_lettersb4(setting &a, const int &value)
}
int
get_numbers
(
setting
&
a
,
std
::
string
line
)
{
{
std
::
istringstream
iss
(
line
);
std
::
string
token
;
std
::
string
range
;
std
::
vector
<
int
>
vector
;
std
::
vector
<
int
>
vector
;
int
number_of_elements
=
0
;
while
(
std
::
getline
(
iss
,
token
,
';'
))
...
...
@@ -121,9 +115,9 @@ int get_numbers(setting &a, std::string line)
char
start
,
end
;
int
range
=
0
;
sscanf
(
token
.
c_str
(),
"SUM(%c:%c)"
,
&
start
,
&
end
);
range
=
end
-
start
+
1
;
if
(
range
>
number_of_elements
)
{
range
=
end
-
start
+
1
;
if
(
range
>
number_of_elements
)
{
get_error_101
(
a
);
}
vector
.
push_back
(
get_sum
(
vector
,
range
));
...
...
@@ -141,16 +135,17 @@ int get_numbers(setting &a, std::string line)
}
vector
.
push_back
(
tmp
);
number_of_elements
++
;
}
catch
(
const
std
::
exception
&
e
)
}
catch
(
const
std
::
exception
&
e
)
{
get_error_101
(
a
);
}
}
}
a
.
numbers
.
push_back
(
vector
);
if
(
number_of_elements
>
a
.
max_size_vector
)
if
(
number_of_elements
>
a
.
max_size_vector
)
a
.
max_size_vector
=
number_of_elements
;
return
0
;
}
...
...
@@ -158,80 +153,75 @@ void print_roof(setting &a)
{
std
::
cout
<<
"+"
;
int
adjust
=
0
;
if
(
a
.
header
==
0
)
adjust
=
-
1
;
if
(
a
.
header
==
0
)
adjust
=
-
1
;
for
(
int
i
=
0
;
i
<
a
.
max_size_vector
+
1
+
adjust
;
i
++
)
{
for
(
int
j
=
0
;
j
<
a
.
width
+
2
+
a
.
zaloha
;
j
++
)
std
::
cout
<<
"-"
;
std
::
cout
<<
"-"
;
std
::
cout
<<
"+"
;
}
std
::
cout
<<
std
::
endl
;
}
void
print_ABC
(
setting
&
a
)
void
print_ABC
(
setting
&
a
)
{
char
letter
=
'A'
;
std
::
cout
<<
"| "
<<
std
::
setw
(
a
.
width
+
2
+
a
.
zaloha
)
<<
" |"
;
std
::
cout
<<
(
a
.
align
==
"left"
?
std
::
left
:
std
::
right
);
std
::
cout
<<
"| "
<<
std
::
setw
(
a
.
width
+
2
+
a
.
zaloha
)
<<
" |"
;
std
::
cout
<<
(
a
.
align
==
"left"
?
std
::
left
:
std
::
right
);
for
(
int
j
=
0
;
j
<
a
.
max_size_vector
;
j
++
)
std
::
cout
<<
" "
<<
std
::
setw
(
a
.
width
+
a
.
zaloha
)
<<
letter
++
<<
" |"
;
std
::
cout
<<
" "
<<
std
::
setw
(
a
.
width
+
a
.
zaloha
)
<<
letter
++
<<
" |"
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
print_roof
(
a
);
}
bool
check_num_of_letters
(
setting
&
a
,
const
int
num
)
{
int
tmp_length
=
std
::
to_string
(
num
).
length
();
if
(
tmp_length
>
a
.
width
&&
a
.
stretch
==
0
)
return
true
;
else
return
false
;
if
(
tmp_length
>
a
.
width
&&
a
.
stretch
==
0
)
return
true
;
else
return
false
;
//return (std::to_string(num).length() > a.width && a.stretch == 0);
}
void
print_all_vectors
(
setting
&
a
)
void
print_all_vectors
(
setting
&
a
)
{
for
(
size_t
i
=
0
;
i
<
a
.
numbers
.
size
();
i
++
)
for
(
size_t
i
=
0
;
i
<
a
.
numbers
.
size
();
i
++
)
{
if
(
a
.
header
==
1
)
std
::
cout
<<
"| "
<<
std
::
setw
(
a
.
width
+
a
.
zaloha
)
<<
i
+
1
<<
" |"
;
else
std
::
cout
<<
"|"
;
std
::
cout
<<
(
a
.
align
==
"left"
?
std
::
left
:
std
::
right
);
if
(
a
.
header
==
1
)
std
::
cout
<<
"| "
<<
std
::
setw
(
a
.
width
+
a
.
zaloha
)
<<
i
+
1
<<
" |"
;
else
std
::
cout
<<
"|"
;
std
::
cout
<<
(
a
.
align
==
"left"
?
std
::
left
:
std
::
right
);
for
(
int
j
=
0
;
j
<
a
.
max_size_vector
;
j
++
)
for
(
int
j
=
0
;
j
<
a
.
max_size_vector
;
j
++
)
{
if
(
j
<
a
.
numbers
[
i
].
size
())
if
(
j
<
a
.
numbers
[
i
].
size
())
{
if
(
check_num_of_letters
(
a
,
a
.
numbers
[
i
][
j
]))
if
(
check_num_of_letters
(
a
,
a
.
numbers
[
i
][
j
]))
{
std
::
cout
<<
" "
<<
std
::
string
(
a
.
width
,
'#'
)
<<
" |"
;
std
::
cout
<<
" "
<<
std
::
string
(
a
.
width
,
'#'
)
<<
" |"
;
continue
;
}
std
::
cout
<<
" "
<<
std
::
setw
(
a
.
width
+
a
.
zaloha
)
<<
a
.
numbers
[
i
][
j
]
<<
" |"
;
std
::
cout
<<
" "
<<
std
::
setw
(
a
.
width
+
a
.
zaloha
)
<<
a
.
numbers
[
i
][
j
]
<<
" |"
;
}
else
std
::
cout
<<
" "
<<
std
::
setw
(
a
.
width
+
a
.
zaloha
)
<<
" "
<<
" |"
;
std
::
cout
<<
" "
<<
std
::
setw
(
a
.
width
+
a
.
zaloha
)
<<
" "
<<
" |"
;
}
/*
if(a.header == 0)
std::cout << " " << std::setw(a.width) << " " << " |";
*/
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
print_roof
(
a
);
}
}
void
get_line
(
setting
&
a
)
void
get_line
(
setting
&
a
)
{
std
::
string
line
;
std
::
cout
<<
"zadejte cislo"
<<
std
::
endl
;
while
(
std
::
getline
(
std
::
cin
,
line
))
while
(
std
::
getline
(
std
::
cin
,
line
))
{
if
(
line
.
empty
())
continue
;
if
(
line
.
empty
())
continue
;
get_numbers
(
a
,
line
);
}
}
...
...
@@ -241,8 +231,8 @@ int main()
setting
a
;
get_config
(
a
);
get_line
(
a
);
print_roof
(
a
);
if
(
a
.
header
==
1
)
print_roof
(
a
);
if
(
a
.
header
==
1
)
print_ABC
(
a
);
print_all_vectors
(
a
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment