Preface
Hello, everyone, I’m bigsai, I haven’t seen it for a long time, I really miss it!
In daily life, many people like to play games, because the game has the joy of confrontation and control, and use soul fingering to complete a wave of beautiful operations.
But in fact, your buttons are all corresponding to the method functions in the code to perform operations, and the interface is rendered with a graphical change to make you feel that you are controlling the graphical interface.
Although the bottom layer of the game is the logic built with lines of code, we are not interested in it because the process of writing code is boring and boring. It completely requires brains to abstract a page and execute logic. It is very simple to find when something goes wrong. Half a day... Output and debug various ways to find problems.
For lazy people like us, if you want to exercise your programming ability, the algorithm really enters a kind of infinite loop that is afraid of difficulties. I hope it is simpler or more interesting, and what you write is best to look like some development. You can see, touch, and don’t learn so hard.
No, today I found a website that is very suitable for beginners and intermediate scholars to practice their own programming: codingame — learns programming while playing games!
The homepage of the website is: https://www.codingame.com/start
Website Introduction
When we are learning technology and learning algorithms, we all like to look at some pictures to concretize abstract content, and even if there are some animated pictures that can simulate program execution logic, it is more popular, but often this kind of content There are a lot of bottom layers involved, and the high-quality content is very sparse, but the website I recommend today is really amazing. The first impression of the website is: , is this Xiaobawang? .
Some small game animations switch backgrounds. Looking at the url of codingame, you will never think that this website has anything to do with programming. You will only think of:
- What the hell is this?
- Google Translate to see...
After registering an account and logging in, more content can be displayed. If you 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 perform some exercises. The page will have game problems of various difficulties. These problems have a small game background, rules, and inspection points waiting for you to complete. For example, most of the easy difficulty are characters. Questions such as string, hash, and loop control, and mid-difficulty is more extensive, such as many binary search, bfs, graph theory, etc. If the English is not good, you can compare it with the translation of Chinese and English (dog head 🐶 raise your hand), Those who are interested in hard difficulty can challenge themselves.
For the problems, some are in the form of text, but more are the small games that have animations that are more intuitive.
Another very important thing is that 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
Let me experience with you how to play the easy question. The first thing I clicked in was a question called ASCII Art .
The address is: https://www.codingame.com/ide/puzzle/ascii-art
When I first came in, I felt a sense of black technology. After reading the questions, some friends may be confused. What is this? This program is a bit different from what we usually do. There is no need to complete the whole method like Likou, nor is it different. Acm submits the entire executable code. This program will declare some content in advance. You only need to write the corresponding logic code in the place where it prompts, and all the results need to be printed out.
But attentive friends will find that this is actually very similar to our daily brushing questions, so let's change it, it's nothing different.
The meaning of the title of this question is very simple, I dictate what (may not be standard):
To the airport you often see this cattle batch display screen: (Picture)
Have you ever asked yourself how to display this number on a good old terminal? (How can I make it difficult for myself), we have: with ASCII art .
ASCII art allows you to use characters to represent. To be precise, 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 big 0-9...
Looking at input and output and other requirements
enter
first line: width L The letters expressed in ASCII art. All letters have the same width.
Line 2: Height H in ASCII art. All letters have the same height.
Line 3 : The text to be output T , consisting of n ASCII characters.
few lines of : 161934ffaa92fe string ABCDEFGHIJKLMNOPQRSTUVWXYZ? Expressed in ASCII art (output to the screen result).
output
The text T is in ASCII art.
The characters a to z are displayed as uppercase equivalent characters in ASCII art.
Characters not in the range [az] or [AZ] will be displayed as question marks in ASCII art.
problem analysis:
Although this is a simple question, how to analyze it?
For a given width L and height H, in fact, limits the size of each character in the console . How to understand this, for example, you can understand. For 0, 0s with different widths and heights may look different:
# # # # # # # # # #
# # # # # #
# # # # # # #
# # # #
# # # # # # #
3*3 3*5 4*5
圆润型 瘦长型 标准型
In fact, you can quickly lock the position of each character by limiting the width and height. In terms of storage, it must be a two-dimensional storage (multiple one-dimensional or two-dimensional).
When outputting, calculate the corresponding position according to the character, and the corresponding output is fine. Considering that some novice players may still not understand, I posted 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();//宽
int H = in.nextInt();//高
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();//输入每一行
ch[i]=ROW.toCharArray();//赋值给对应行
}
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;//不是字母统统问号 ???
for(int j=0;j<H;j++){
for(int q=0;q<L;q++)
{
value[j][q+i*L]=ch[j][q+L*index];//赋值给待输出结果
}
}
}
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");
}
}
Just submit it after the test.
mid first experience two points
After reading an easy question, you may feel that there is nothing wrong with it. Then, let's look at a classic mid question together:
The link is: https://www.codingame.com/ide/puzzle/shadows-of-the-knight-episode-1
This question specifically requires that everyone can go to the above to see on their own, but the general meaning is:
Tells you the length and width of the area where , and tells you your initial point .
Your goal is to finally reach a certain end point, without telling you the specific coordinates, but only telling you the position of the target point at your current point (there are eight directions). You need to walk to the target node position within N steps, and you have to output your current point position every time you walk.
When I saw this question I didn't read it too well, I wrote a code that only took one step at a time. As a result, when I encountered a very long map structure, it was GG.
Later, I thought about it and told the location that we can perform a binary search every time and compress the location of the area, which is
Encountered all the U : indicate that the bottom of the is above this point
Encounter all D directions: indicate that the top of the below this point
Encounter all L directions: explain that the rightmost side of the to the left of this point
Encountered all R directions: explain that the leftmost part of the is a bit at this point
By using dichotomy, the previous O(n) time complexity is reduced to O(logn) level, and basically all points can be found.
Personal code can give the big guy 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);
}
}
}
View the test case results as:
Of course, for each test case, you can scroll to see the animation corresponding to each round 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 Daguai upgrade, which is a bit interesting.
Summarize
For such a website, it is very friendly to stimulate the interest of beginners in programming. It is recommended that three or two teammates fight monsters and upgrade together, or roommates can compete with each other. Throw this question in the dormitory group for everyone to take a look and see who comes first. Do it right.
However, any tool must be selected and used. You can find some challenging but acceptable problems to try. It's fun to have fun and experience!
Personal public number: bigsai
Welcome to follow
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。