Interview Enterprise Shell programming basic problem Solving practice (pro-Test)

Source: Internet
Author: User

The problem is to choose the old boy teacher blog inside of the problem, extrapolate of which also extended two questions.

Old boy teacher's blog address http://oldboy.blog.51cto.com/2561410/1718607


Anyway


1. Use the shell or Python to write a square that receives the number entered by the user.

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/84/4D/wKioL1eMbpiCbzCIAAAftdE6HW8430.jpg-wh_500x0-wm_3 -wmp_4-s_3091629460.jpg "style=" Float:none; "title=" psb1.jpg "alt=" Wkiol1embpicbzciaaaftde6hw8430.jpg-wh_50 "/>

Method: Vim zhong1.sh

#!/bin/bashread-p "Please Enter a number:" N for ((x=1;x<= $n; x + +));d O for ((y=1;y<= $n *2;y++)) do Echo-n " + "do echo" "Done"


Example 2: implementation by number (zhong2.sh)

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/4D/wKiom1eMbpiDbFsqAAAQvnpxzcI105.jpg-wh_500x0-wm_3 -wmp_4-s_2967627548.jpg "style=" Float:none; "title=" psb2.jpg "alt=" Wkiom1embpidbfsqaaaqvnpxzci105.jpg-wh_50 "/>

Method: Vim zhong2.sh

#!/bin/bashread-p "Please Enter a number:" N for ((x=1;x<= $n; x + +));d O for ((y=1;y<= $n; y++)) do Echo-n " "Done Echoes" "done


  2. Use the shell or Python to write a isosceles triangle that receives the number entered by the user.

For example: implemented with the * number (zhong3.sh)

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/4D/wKioL1eMbpiTDyWEAAAmZ28D6Uo780.jpg-wh_500x0-wm_3 -wmp_4-s_4224570038.jpg "style=" Float:none; "title=" psb3.jpg "alt=" Wkiol1embpitdyweaaamz28d6uo780.jpg-wh_50 "/>

Method: Vim zhong3.sh

#!/bin/bashread-p "Please Enter a number:" N for ((x=1;x<= $n; x + +));d O for ((z=1;z<= $n-x;z++));d o echo-n "" Done for ((y=1;y<=a+1;y++));d o echo-n "*" Did Echo a=$ ((a+2)) done


3 . Please write an inverted isosceles triangle with the shell or Python to receive the user input numbers. (continuation of the second question)

For example: implemented with the * number (zhong33.sh)

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/84/4D/wKiom1eMbpmALiJfAAAfJ3xdErw315.jpg-wh_500x0-wm_3 -wmp_4-s_1089656928.jpg "style=" Float:none; "title=" psb4.jpg "alt=" Wkiom1embpmalijfaaafj3xderw315.jpg-wh_50 "/>

Method: Vim zhong33.sh (can be changed on the basis of zhong3.sh)

#!/bin/bashread-p "Please Enter a number:" N for ((x=1;x<= $n; x + +));d O for ((z=0;z<x-1;z++));d o echo-n "" Done for ((y=1;y<= $n-(a+1-$n); y++);d o echo-n "*" Do Echo a=$ ((a+2)) done


4 . Please write a diamond in shell or Python to receive the user input. (continuation of the second question)

For example: implemented with the * number (zhong333.sh)

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M00/84/4D/wKioL1eMbpmAz3j8AAA2tkJ28Po115.jpg-wh_500x0-wm_3 -wmp_4-s_3298491014.jpg "style=" Float:none; "title=" psb5.jpg "alt=" Wkiol1embpmaz3j8aaa2tkj28po115.jpg-wh_50 "/>

method: Vim zhong333.sh

 #!/bin/bashread -p  "Please enter a number : " n for  ((x=1;x<= $n; x + +);d o     for  ((z=1;z<= $n-x;z++)); do    echo -n  " "     done    for   ((y=1;y<=a+1;y++));d o    echo -n  "*"     done     echo     a=$ ((a+2)) doneb=2for  ((x=1;x<= $n; x + +));d o     for  ((z=0;z<=x-1;z++));d o      echo -n  "       done    for  ((y=1;y<= $n-(b+1-$n); y++);d o       echo -n  "*"     done    echo     b=$ ((b+2)) Done 


5. Use shell or Python to write a right-angled trapezoid program that receives user input parameters N,m

For example: implemented with the * number (zhong4.sh)

650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M02/84/4D/wKiom1eMbpnhI7MjAABUVcuEo4E559.jpg-wh_500x0-wm_3 -wmp_4-s_2815179913.jpg "style=" Float:none; "title=" psb6.jpg "alt=" Wkiom1embpnhi7mjaabuvcueo4e559.jpg-wh_50 "/>

Method: Vim zhong4.sh

#!/bin/bashfor ((x=1;x<=$2;x++));d O for ((y=1;y<=$1+a;y++)) does echo-n "+" Done a=$ ((a+1)) echo " "Done


The above results are pro-measured, can fully achieve the requirements of the topic

Linux environment: Linux 51master 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 04:27:16 UTC x86_64 x86_64 x86_64 gnu/linux

This article is from the "Cloud Operations" blog, be sure to keep this source http://ycentos.blog.51cto.com/10297565/1827378

Interview Enterprise Shell programming basic problem Solving practice (pro-Test)

Related Article

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.