preface
hello, everyone, I'm bigsai. I haven't seen you for a long time. I miss you very much!
In daily life, many people like to play games, because the game has the joy of confrontation and control, and completes a wave of beautiful operations with soul fingering.
But in fact, your keys are corresponding to each method function in the code to perform operations, and the interface achieves a graphical change rendering, which makes you feel that you control the graphical interface.
Although the bottom layer of the game is logic piled up in lines of code, we are not interested in it at all, because the process of writing code is boring and boring. It completely requires the brain to abstract a page and execute logic. When there is an error, we simply look for it for a long time... Output and debug various ways to find the problem.
For lazy people like us, if we want to exercise our programming ability and algorithms, we really enter an infinite loop of fear of difficulties. We hope to be either simpler or more interesting. It's best to write things that can be seen and touched like some developers, so it's not so difficult to learn.
Today, I found a website that is very suitable for junior and intermediate scholars to practice their own programming: codingame - a website that learns programming while playing games!
The website home page is: https://www.codingame.com/start
Website introduction
When learning technology and algorithms, we all like to look at some diagrams to concretize the abstract content. Even if there are some dynamic diagrams, it will be more popular if we can simulate the program execution logic. However, this kind of content often involves a lot of bottom layers, and the high-quality content is very sparse, But the website I recommend today is really amazing. The first feeling of entering the website is: lying in the slot. Is this a bully? What the hell.
Some small game animations switch the background. Looking at the url of codingame, you don't think that this website has anything to do with programming. You just think:
- What the hell is this?
- Google translate
After registering an account and logging in, more content can be displayed. Look carefully. There are still some codes on the right side of the background, and there are still some very mysterious feelings.
After logging in, the practice in the upper left corner can do some exercises. There will be game problems with various difficulties on the page. These problems have a small game background, rules and inspection points waiting for you to complete. For example, most of the easy difficulties are string, hash and loop control problems, while the mid difficulties have wider inspection points, such as many binary search, bfs, graph theory, etc, If English is not good, you can compare it between Chinese and English with the help of translation πΆ Raise your hand). If you are interested in hard difficulty, you can challenge yourself.
For these problems, some are in the form of text, but more are small games, and animation is more intuitive.
Another very important thing is that it supports multiple programming languages. No matter you are a fan of the mainstream language, you can imagine the joy of learning programming while playing games.
easy first experience: the art of ASCII
Here, let's experience how to play the easy problem. The first thing I click in is a problem called ASCII Art
The address is: https://www.codingame.com/ide...
I just came in with a strong sense of black technology. After reading the questions, some friends may be confused. What's this? This program is a little different from what we usually see. It doesn't need to complete the whole method like force buckle, nor submit the whole executable code with acm, This program will declare some contents in advance. You only need to write the corresponding logic code where it prompts, and all the results should be printed.
But careful friends will find that this is actually very similar to our daily problem brushing. Don't change it. It's no different.
The meaning of this question is also very simple. Let me dictate it (it may not be standard):
To the airport, you often see the display screen of this cattle batch: (picture)
Have you ever asked yourself how to display this number on a good old terminal? (how can I be difficult for myself), we have: using ASCII art.
ASCII art allows you to use characters to represent. To be exact, in our example, these forms are words. For example, the word "MANHATTAN" can be displayed in ASCII art as follows:
This is a bit familiar. I also printed large 0-9
Looking at input and output and other requirements
input
Line 1: letter with width L expressed in ASCII art. All letters have the same width.
Line 2: letter with height H expressed in ASCII art. All letters have the same height.
Line 3: text T to be output, consisting of n ASCII characters.
The following lines: string ABCDEFGHIJKLMNOPQRSTUVWXYZ? Expressed in ASCII WordArt (output to screen results).
output
Text T in ASCII art.
The characters a through z appear as uppercase equivalents in ASCII art.
Characters not in the interval [AZ] or [AZ] will be displayed as question marks in ASCII art.
Problem analysis:
Although this is a simple problem, how to analyze it?
For a given width L and height H, it actually limits the size of each character on the console. How to understand this? For example, you can understand. For 0, 0 with different width and height may look different:
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # 3*3 3*5 4*5 Round and slender Standard type
In fact, you can quickly lock the position of each character by limiting its width and height. In terms of storage, you don't have to think about it. It must be a two-dimensional storage (multiple one-dimensional or two-dimensional).
At the time of output, calculate the corresponding position according to the characters, and the corresponding output is OK. Considering that some small white players may not understand it, I pasted my own πΆπ Code, for reference only:
import java.util.*; import java.io.*; import java.math.*; /** * Auto-generated code below aims at helping you parse * the standard input according to the problem statement. **/ class Solution { public static void main(String args[]) { Scanner in = new Scanner(System.in); int L = in.nextInt();//wide int H = in.nextInt();//high char ch[][]=new char[H][L]; if (in.hasNextLine()) { in.nextLine(); } String T = in.nextLine().toUpperCase(); for (int i = 0; i < H; i++) { String ROW = in.nextLine();//Enter each line ch[i]=ROW.toCharArray();//Assign to corresponding row } char value[][]=new char[H][T.length()*L]; for(int i=0;i<T.length();i++){ char temp=T.charAt(i); int index=temp-'A'; if(index<0||index>26) index=26;//Not all the letters, question marks??? for(int j=0;j<H;j++){ for(int q=0;q<L;q++) { value[j][q+i*L]=ch[j][q+L*index];//Assign to the result to be output } } } for(char tem[]:value){ for(char temp:tem){ System.out.print(temp); } System.out.println(); } // Write an answer using System.out.println() // To debug: System.err.println("Debug messages..."); //System.out.println("answer"); } }
Submit after testing.
mid initial experience dichotomy
After reading an easy question, you may feel that it's nothing. OK, let's look at a classic mid question:
The link is: https://www.codingame.com/ide...
This question requires you to look at it by yourself, but the general meaning is:
Tell you the length and width of the area you are in, and tell you your initial point.
Your goal is to finally reach a certain end point. It doesn't tell you the specific coordinates, but only the orientation of the target point at your current point (there are eight directions). You need to go to the target node within N steps, and you have to output the position of your current point every round.
When I saw this problem and didn't understand it very well, I wrote a code that only goes one step at a time. As a result, I encountered a very long map structure, which is GG.
Later, I thought about it and told the azimuth that we can perform binary search each time and compress the location of the area, that is
Encounter all U directions: it means that the bottom of the map is above this point
Encounter all D directions: it means that the top of the map is below this point
Encounter all L directions: it means that the rightmost side of the map is to the left of this point
Encounter all R directions: it means that the leftmost part of the map is a little at this point
By using dichotomy, the previous O(n) time complexity is reduced to the O(logn) level, and basically all points can be found.
Personal code can give big guys a small reference:
import java.util.*; import java.io.*; import java.math.*; /** * Auto-generated code below aims at helping you parse * the standard input according to the problem statement. **/ class Player { public static void main(String args[]) { Scanner in = new Scanner(System.in); int W = in.nextInt(); // width of the building. int H = in.nextInt(); // height of the building. int N = in.nextInt(); // maximum number of turns before game over. int X0 = in.nextInt(); int Y0 = in.nextInt(); int u=0,d=H,l=0,r=W; // game loop while (true) { String bombDir = in.next(); // the direction of the bombs from batman's current location (U, UR, R, DR, D, DL, L or UL) // Write an action using System.out.println() // To debug: System.err.println("Debug messages..."); if(bombDir.contains("U")){ d=Y0; Y0=((u+Y0)/2); } if(bombDir.contains("D")){ u=Y0+1; Y0=((d+Y0)/2); } if(bombDir.contains("L")){ r=X0; X0=((l+X0)/2); } if(bombDir.contains("R")){ l=X0; X0=((r+X0)/2); } // the location of the next window Batman should jump to. System.out.println(X0+" "+Y0); } } }
The test case results are:
Of course, for each test case, you can scroll to see the corresponding animation of each round in the middle of the test, which is quite nice.
In this way, the code you write can visually see the results of each step running on the image, just like playing strange and upgrading. It's a little interesting.
summary
For such a website, the stimulation of beginners' interest in programming is still very friendly. It is recommended that three or two teammates play strange upgrades together, or roommates compete with each other. Throw this question into the dormitory group and let everyone have a look to see who does it right first.
However, any tool should be selected and used. You can find some challenging but acceptable problems to try. It's fun to play and experience!
Official account No. bigsai: welcome.