The conventional problem solving method of algorithm problem

Source: Internet
Author: User

First look at a programming question: the string "I am Chinese man a better man" in reverse order to become "man better a man Chinese am I".

 Public class reversestring {    publicstaticvoid  main (String args[]) {        = "I am a" Chinese man a better Man ";         = Message.split ("");          for (int i = array.length-1;i >= 0; i--) {            System.out.print (Array[i]+ "");}}}    

steps and errors for problem resolution:
1. Resolve the problem, manually "solve"
(1) for children and adults, this step is more difficult for the former
(2) However, if a student who has misunderstood the problem is asked to reread the question, the child will perform more than the adult
2. Come up with a pseudo-code algorithm
(1) In this step, students perform better than adults.
(2) It is shocking that many adults do not know how to extract a single character from a string in their preferred programming language.
3. Convert the algorithm to code
(1) we have C + + programmers who do not know the square brackets and some C programmers who use pointer arithmetic but fail.
(2) More surprisingly, when they allow access to the Java API documentation or use reference books, many adults cannot find the right documentation to help solve the problem.
(3) It is true that some middle school students have forgotten how to use the stack or instantiate a queue, but everyone can find a solution in the right time through a lookup.
(4) Adults who write code often exceed the time limit.

There are a lot of bad code writers, even if you're one of them, don't be afraid .
You can try the following methods:
1. Keep practicing until you are able to write small snippets quickly and correctly. There is no reason to write a double loop in your favorite language. Find some small code puzzles with examples that you can understand in less than a minute. Do hundreds or thousands of exercises on this type of problem (not just dozens of times, remember!) )。
2. Write a list of use cases for each algorithm in the textbook. One common mistake is to just remember the computational complexity table. But looking at some examples of algorithms, such as where A * search is used, is much more useful than learning the code itself.
3. Do at least one large project that will force you to use work-related interfaces/use cases. Language is usually not very important, and writing a large project alone can force you to learn new design patterns and stay away from legacy code maintenance. Code interviews are intelligence tests. So they pay little attention to specific systems.
4. Get yourself in touch with better programmers. With the rapid growth of CS post, the current solution to the "lemon market" is technical interviewing. But there are other ways to reflect the interviewees ' information. For example, knowledge of hot topics, blogs, and technology can reflect awareness of important issues. Similarly, the use of humorous code notation for horror stories can reflect experience and the ability to deal with new problems. Fortunately, the online code-writing community is ubiquitous, so the only obstacle is the willingness to spend time and remain humble.

Looking at a programming question: the probability of pumping A is 1/6. The probability of pumping in B is 5/6.

 Public classLottery { Public Static voidMain (string[] args) {if(Draw ()) {System.out.println ("You have get A"); }Else{System.out.println ("You hava get B"); }    }    StaticBoolean Draw () {inttemp = (int) (Math.random () *6);        SYSTEM.OUT.PRINTLN (temp); if(temp = = 0){            return true; }Else {            return false; }    }}

Again: In a two-dimensional array, each row is ordered in ascending order from left to right, and each column is sorted according to the sequence of books ascending from top to bottom. Complete a function like this, enter a two-dimensional array and an integer to determine whether the integer is in the array.

 Public classTestarray { Public Static voidMain (String args[]) {int[] Array = {{1,2,3,4,5},                          {2,3,4,5,6},                          {3,4,5,6,7},                          {4,5,6,7,8},                          {5,6,7,8,9}}; intnum = 9; if(Justify (Array,num)) {System.out.println ("The array has number:" +num); }Else{System.out.println ("The array has not find number:" +num); }    }        StaticBoolean Justify (int[] Array,intnum) {        intLen = array[0].length > Array.Length? Array.length:array[0].length; Boolean Flag=true;  for(inti = 0; i < len-1; i++){            if((array[0][0] > num) | | (Array[array.length-1][array[0].length-1] <num)) {Flag=false; }            if((array[0][0] < num) && (Array[i][i] >=num)) {                Booleanout=true;  for(intk = 0; (k <= i) && (out); k++){                     for(intm = 0; (M <= i) && (out); m++){                        if(Array[k][m] = =num) {Flag=true; out=false; }Else{flag=false; }                    }                }            }        }        returnFlag; }}

The conventional problem solving method of algorithm problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.