Editing
2015 Dec Bronze Problem 1 Fence Painting
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Java === <pre> import java.io.*; import java.util.*; public class Paint { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new FileReader("paint.in")); PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("paint.out"))); StringTokenizer st = new StringTokenizer(br.readLine()); int segment1Start = Integer.parseInt(st.nextToken()); int segment1End = Integer.parseInt(st.nextToken()); st = new StringTokenizer(br.readLine()); int segment2Start = Integer.parseInt(st.nextToken()); int segment2End = Integer.parseInt(st.nextToken()); int paintedLength; // Checking overlap scenarios if(segment2Start >= segment1End) { // No overlap paintedLength = (segment1End - segment1Start) + (segment2End - segment2Start); } else if(segment2End > segment1End) { // Partial overlap with segment2 exceeding segment1 paintedLength = segment2End - segment1Start; } else { // Full overlap where segment2 is completely inside segment1 paintedLength = segment1End - segment1Start; } pw.println(paintedLength); pw.close(); } } </pre>
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information