Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
5
5bhit
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
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
Hamm Daniel
5bhit
Commits
ba612f8f
Commit
ba612f8f
authored
1 year ago
by
DerechteDani
Browse files
Options
Downloads
Patches
Plain Diff
nix
parent
bd739dbc
Branches
master
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
sew5/bin/.gitignore
+2
-0
2 additions, 0 deletions
sew5/bin/.gitignore
sew5/src/ccc/lvl1.java
+70
-0
70 additions, 0 deletions
sew5/src/ccc/lvl1.java
with
72 additions
and
0 deletions
sew5/bin/.gitignore
+
2
−
0
View file @
ba612f8f
...
...
@@ -11,3 +11,5 @@
/synchro/
>>>>>>> branch 'master' of https://git.htltraun.at/T90016/5bhit.git
/phonebook/
/level1/
/ccc/
This diff is collapsed.
Click to expand it.
sew5/src/ccc/lvl1.java
0 → 100644
+
70
−
0
View file @
ba612f8f
package
ccc
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.nio.file.Files
;
import
java.nio.file.Paths
;
import
java.util.List
;
public
class
lvl1
{
public
static
void
main
(
String
[]
args
)
{
try
{
String
filename
=
"C:\\Users\\walle\\Downloads\\level2\\level2_1."
;
List
<
String
>
in
=
Files
.
readAllLines
(
Paths
.
get
(
filename
+
"in"
));
// Extracting input data from the list
int
N
=
Integer
.
parseInt
(
in
.
get
(
0
));
// Number of currencies
int
lineIndex
=
1
;
// Current index in the input list
StringBuilder
outputBuilder
=
new
StringBuilder
();
// For storing output
for
(
int
i
=
0
;
i
<
N
;
i
++)
{
int
C
=
Integer
.
parseInt
(
in
.
get
(
lineIndex
++));
// Number of coin values per currency
int
A
=
Integer
.
parseInt
(
in
.
get
(
lineIndex
++));
// Number of amounts per currency
for
(
int
j
=
0
;
j
<
A
;
j
++)
{
String
[]
currencyValuesStr
=
in
.
get
(
lineIndex
++).
split
(
" "
);
int
[]
currencyValues
=
new
int
[
C
];
for
(
int
k
=
0
;
k
<
C
;
k
++)
{
currencyValues
[
k
]
=
Integer
.
parseInt
(
currencyValuesStr
[
k
]);
// Parse currency values
}
int
amount
=
Integer
.
parseInt
(
in
.
get
(
lineIndex
++));
// Amount to construct
// Find a pair of values that sum up to the amount
int
value1
=
-
1
,
value2
=
-
1
;
for
(
int
m
=
0
;
m
<
C
;
m
++)
{
for
(
int
n
=
m
;
n
<
C
;
n
++)
{
if
(
currencyValues
[
m
]
+
currencyValues
[
n
]
==
amount
)
{
value1
=
currencyValues
[
m
];
value2
=
currencyValues
[
n
];
break
;
}
}
if
(
value1
!=
-
1
&&
value2
!=
-
1
)
{
break
;
}
}
// Append the pair to the output
outputBuilder
.
append
(
value1
).
append
(
" "
).
append
(
value2
).
append
(
"\n"
);
}
}
// Writing output to file
File
myObj
=
new
File
(
filename
+
"out"
);
if
(
myObj
.
createNewFile
())
{
System
.
out
.
println
(
"File created: "
+
myObj
.
getName
());
}
else
{
System
.
out
.
println
(
"File already exists."
);
}
FileWriter
myWriter
=
new
FileWriter
(
filename
+
"out"
);
myWriter
.
write
(
outputBuilder
.
toString
());
// Write the output to file
myWriter
.
close
();
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
}
}
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