Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
gcj2023
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
Service Desk
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
insertsomethingwitty
gcj2023
Commits
6a1e1d6b
Unverified
Commit
6a1e1d6b
authored
2 years ago
by
Simon Leinen (SWITCH)
Browse files
Options
Downloads
Patches
Plain Diff
Initial version giving Wrong Answer
parents
Loading
Loading
Loading
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
c/1.lisp
+58
-0
58 additions, 0 deletions
c/1.lisp
with
58 additions
and
0 deletions
c/1.lisp
0 → 100644
+
58
−
0
View file @
6a1e1d6b
;;;; Game Sort
(
defun
solve
(
&optional
(
in
*standard-input*
))
(
dotimes
(
caseno
(
the
(
integer
0
1000
)
(
read
in
)))
(
format
t
"Case #~D: "
(
+
caseno
1
))
(
solve-case
in
)))
(
defun
solve-case
(
in
)
(
let
((
nchunks
(
read
in
)))
(
let
((
line
(
read-line
in
)))
(
let
((
chunks
(
split-at-spaces
line
nchunks
)))
(
let
((
sol
(
gamesort
chunks
)))
(
if
sol
(
format
t
"POSSIBLE~%~{~A~^ ~}~%"
sol
)
(
format
t
"IMPOSSIBLE~%"
)))))))
(
defun
split-at-spaces
(
s
n
)
(
do*
((
n
n
(
1-
n
))
(
result
'
())
(
k
0
)
(
next
(
position
#\Space
s
:start
k
)
(
position
#\Space
s
:start
k
)))
((
zerop
n
)
(
nreverse
result
))
(
push
(
subseq
s
k
next
)
result
)
(
when
next
(
setq
k
(
+
next
1
)))))
(
defun
gamesort
(
strings
)
(
gamesort-1
strings
""
'
()))
(
defun
gamesort-1
(
strings
last
result
)
(
if
(
endp
strings
)
(
nreverse
result
)
(
let
((
next
(
sort-after
(
first
strings
)
last
)))
(
if
next
(
gamesort-1
(
rest
strings
)
next
(
cons
next
result
))
nil
))))
(
defun
sort-after
(
s1
s2
)
(
sort-after-1
(
sort
(
coerce
s1
'list
)
#'
char<
)
s2
0
'
()))
(
defun
sort-after-1
(
c1
s2
pos
result
)
(
let
(
next
)
(
let
((
tentative-result
(
coerce
(
append
(
reverse
result
)
c1
)
'string
)))
(
if
(
string>=
tentative-result
s2
)
tentative-result
(
if
(
or
(
>=
pos
(
length
s2
))
(
endp
c1
)
(
progn
(
setq
next
(
find
(
char
s2
pos
)
c1
:test
#'
char<=
))
(
not
next
)))
nil
(
sort-after-1
(
remove
next
c1
:count
1
)
s2
(
+
pos
1
)
(
cons
next
result
)))))))
(
solve
)
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