ruby programming exercises

Want to know ruby programming exercises? we have a huge selection of ruby programming exercises information on alibabacloud.com

Geek Programming Exercises--zigzag matrices

one square.If the element in the two-dimensional array m[i][j] coordinates i is odd, and j=0 or j=7, then the Traverse path in the matrix is moving vertically down one grid.Code 2#include #include #include using namespace STD;intMain () {intNCin>> N; vectorint>VEC (N*n);intx=0, y=0; for(inti =0; i for(intj =0; J //boundary steering divided into odd and even two cases //Odd cases are divided into upper and lower triangles for processing ifN2) {//Upper triangle

First-time programming exercises

=POINT2+POINT4;cout}Else{POINT1=POINT1+POINT4;POINT2=POINT2+POINT4;POINT3=POINT3+POINT4;cout}}else if (ast4[0]== ' R ' ast4[1]== ' o ' ast4[2]== ' t ' ast4[3]== ' a ' ast4[4]== ' t ' ast4[5]== ' E ' ast4[6]==0){cin>>ast5;cin>>avg;Deg=avg/180*pi;Rot (0,0) =cos (deg);Rot (0,1) =sin (deg);Rot (1,0) =-sin (deg);Rot (=cos) (deg);if (n==1){Point1=point1*rot;cout}else if (n==2){Point1=point1*rot;Point2=point2*rot;cout}Else{Point1=point1*rot;Point2=point2*rot;Point3=point3*rot;cout} }Else{cout}return 0;

Geek programming Exercises-the longest same substring

TopicsEnter a line of string to find the same and longest string that appears, outputting it and the position of the first character.InputyyabcdabjcabcegOutputabc3parsingFirst declare that if the string is aaaaaa, the answer should be aaaaa. Two equal-length substrings can have some overlapping characters.Take Abcab as an example to analyze the following:First look for substrings of length 4, only ABCA and Bcab, and then see if the two substrings have other identical substrings. Some words direc

Chapter III Programming Exercises 3.1

Packageexercise3;ImportJava.util.Scanner; Public classMain1 { Public Static voidMain (string[] args) {Scanner input=NewScanner (system.in); DoubleA =input.nextdouble (); Doubleb =input.nextdouble (); Doublec =input.nextdouble (); DoublePanbieshi = b*b-4*a*C; if(Panbieshi ) {System.out.println ("No value"); } Else if(Panbieshi = = 0) { DoubleR1 =-b/(a); SYSTEM.OUT.PRINTLN (R1); }Else{ DoubleR1 = (-B + math.pow (Panbieshi, 0.5))/(2 *a); Doubler2 = (-b-ma

Ka recursive programming exercises part2| the positive sequence output, arithmetic progression and

1#include 2 voidPP (intN)3 {4 if(n==0)return;5PP (n/Ten);6printf"%d", n%Ten);7 }8 voidNP (intN)9 {Ten if(n==0)return; Oneprintf"%d", n%Ten); APP (n/Ten); - } - intAd (intN) the { - if(n==0)return 0; - if(n==1)return 1; - returnAd (n1)+N; + } - intMain () + { A intN; atscanf"%d",n); -printf"%d\n", Ad (n)); - PP (n); -printf"\ n"); - NP (n); - return 0; in}PP is the positive sequence, NP is reverse order, ad is a series and.The difference between PP and NP is that, as t

C and Pointers chapter two programming exercises

character constant. Intmain () {inti=0;charstr[1000] ={0};intcount=0; printf ("Please enter: \ n"); NBSP;NBSP;NBSP;NBSP;SCANF ("%s", str);while (Str[i] != ' \ n ') {if (str[i]== ' {') { count++;}if ( str[i]== '} ') (count==0) { count--; break;}if ((str[i) == '} ') (count!=0)) { count--;} i++;}if (count==0) {printf ("All curly braces appear in pairs \ \");} else{printf ("Curly braces do not appear in pairs \ \"); }system ("pause"); return0;}This article is from the "Sean" blog, so be sure to

Sixth Chapter programming Exercises

First question1#include 2#include 3 using namespacestd;4 intMain ()5 {6 Chararr[ the];7 Charch;8Cin.getline (arr, the);9 intI=0;Tench=arr[0]; One while((ch!='@') (i the)) A { - if((ch>='a') (ch'Z')) coutChar(ToUpper (CH)); - Else if((ch>='A') (ch'Z')) coutChar(ToLower (CH)); the Elsecoutch; -i++; -Ch=Arr[i]; - } + return 0; -}Second question1#include 2#include 3 using namespacestd;4 intMain ()5 {6 Doubletemp;7 Doubledonation[Ten];8

"Programming Zhu Ji Nanxiong" (2nd edition) Chapter One ": After-school exercises

to the height of the right sub-tree. The key values can be traversed from small to large using the middle order traversal (with iterators).Refer to Cplusplus for a more detailed description of the set container.The specific code is as follows:1#include 2#include Set>3 using namespacestd;4 5 intMain ()6 {7 intMyints[] = { $, at, the, the, - };8 Setint> MySet (myints, myints +5);//Use the ' Set ' member function ' Insert ' is also OK.9 Ten Setint>::iterator ITR =Myset.begin (); One

Python core Programming The answer to the second edition of the exercises

()Choice=input ("Please choice One:")If choice==1:Sum=sum ()Print "sum is%d"%sumElif choice==2:Ave=ave ()Print "average is%f"%aveElif choice== ' x ':BreakElsePrint "Wrong choice,please choose again!"2-15#让用户输入3个数值并将分别将他们保存到3个不同的变量中, do not use a list or sorting algorithm#从小到大While True:Num1=int (raw_input ("Please input NUM1:"))Num2=int (raw_input ("Please input num2:"))Num3=int (raw_input ("Please input num3:"))If num1>num2:Tmp=num1Num1=num2Num2=tmpIf num2>num3:Tmp=num2Num2=num3Num3=tmpIf num1

Python core programming Exercises-sixth chapter

: - Print "Invalid:first symbol must be alphabetic" + elifMyinputinchKW: A Print "invalid:it a python keyword" at Else: - forOthercharinchMyinput[1:]: - ifOtherchar not inchAlphas +Nums: - Print "invalid:remaining symbols must be alphanumeric" - Break - Else: in Print "Okay as an identifier"3. Sorting(a) Enter a series of numbers and arrange them from large to small.(b) Same as a, but in dictionary

Python core programming chapter sixth exercises

6-6 Creating a similar String.strip () functionMethod an inefficient method for copying and generating substring objects in large numbers def Str_strip (s):While Len (s) >=2:If s[0]== ':S=s[1:]ElseBreakWhile Len (s) >=2:If s[-1]== ':S=S[:-1]ElseBreakIf s== ' or s== ':Return 'Elsereturn s Method Two: Convert to List def Str_strip (s): if s = = "or S = =" ": Return "" #to List Elif Len (s) >=2: L = List (s) While L and l[0] = = "":

Java Basics-Programming exercises (III)

"." Location of the number - intindex = Name.lastindexof ('. ')); Wu //get the suffix of a file -String prefix =name.substring (index); About $ //The judgment must contain the "." Number, and cannot appear in the first place, with the suffix named "java" - if(Index! =-1 Index! = 0 prefix.equals (". Java")) { - - return1; A } + } the return-1; - $}Operation Result:This is in accordance wi

Java Programming Ideas Fourth Edition Chapter two answers to the exercises

table is not used at all. Compile with Javac, and then run it in Java. If you're using a different development environment than the JDK, learn how to compile and run it in your environment Public class javathinking { publicstaticvoid main (string[] args) { System.out.println ("Hello,world");} }Exercise 3: Find the code snippet that contains the atypename, rewrite it as a complete program, and then compile, runclass atypename{ public atypename () { System.out.println

android--Multithreaded Programming Exercises

(inti=0;i) the { - if(i%2==0) in { theC2= ""; the } About Else the { theC2= "Shanghai"; the } +Runonuithread (NewRunnable () { - @Override the Public voidrun () {Bayi Tvw2.settext (C2); the } the }); - //Pause - Try { theThread.Sleep ((int) (Math.random (

Python Core Programming Second Edition second chapter exercises

2.12.32.42.52.62.72.82.92.102.11deftest_sum (): Tup=("1","2","3","6","5") Sum=0 forIinchTup:sum=float (i) +sumreturnsumdeftest11 (): whiletrue:string=raw_input (">>") ifstring=="1": Sum=test_sum ()Print "sum:", Sumelifstring=="2": Sum=test_sum () Avg=sum/5Print"avg:", Avgelifstring=="x": Exit ()Else: Print"Please enter 1 or 2 or x"test11 ()2.12-2.132.15B:deftest15 (): Num1=raw_input ("First num:") num2=raw_input ("Second num:") num3=raw_input ("Third num:") NUM1=float (NUM1) nu

Bash Shell programming Exercises

~/tscripts $ unset namereadonly6. Non-read-only variable can be canceled, cancel print to empty[Email protected] ~/tscripts $ unname=~/~/tscripts $ echo $unname7. Single quotation marks~ $ name='Leo'$name ' $'name'8. Double quotes" I am $name " "\\i am $name \ \"\i am Leo \9. Stitching strings" He is $name " is "$name is handsome"! is handsome! "$name is handsome! "-bash:! " : Event not found10. Get the string length[Email protected] ~ $ echo ${#name}311. Extracting A String[Email protecte

Java Programming (13.2)----craps gambling game design, comprehensive application exercises

, 50); B3.setbounds (670, +, +), This.add (B1); This.add (B2); This.add (b3); This.add (JL1); This.add (JL2); This.add (JL3);} /** * Rewrite: Paint method */@Overridepublic void Paint (Graphics g) {super.paint (g); if (P1! = null P2! = null) {P1.draw (g , P1.getpoint ()-1, 2.draw (g, P2.getpoint ()-1, 425, 100);p;}}The window is a bit big ... Too lazy to adjust ...3.Package com.lovo.homework;/** * Class: Actuator? * @author Abe */public class Crapstest {public static void main (string[] args) {

java-Set Programming Exercises

("**************************"); System.out.println ("Please enter the action you have chosen:"); } Public Static voidMain (string[] args) {Carmanager cm=NewCarmanager (); Cartest CT=Newcartest (); Ct.menu (); Scanner SC=NewScanner (system.in); while(true) { intn =Sc.nextint (); Switch(n) { Case1: Cm.add (); Ct.menu (); Continue; Case2: Cm.show (); Ct.menu (); Continue; Case3: Cm.changbrand (); Ct.menu (); Continue; Case4: Cm

Java_ Basic Grammar programming exercises

corresponding informationSystem.out.print ("Please enter any number of 1-7:"); Scanner SC=NewScanner (system.in); intWeek =Sc.nextint (); Switch(week) { Case1: System.out.println ("Today is Monday"); Break; Case2: System.out.println ("Today is Tuesday"); Break; Case3: System.out.println ("Today is Wednesday"); Break; Case4: System.out.println ("Today is Thursday"); Break; Case5: System.out.println ("Today is Friday"); Break; Case6: System.out.println ("Today is Saturday"); Break; Ca

"Python Programming Quick Start" 8.9.2 practical exercises

First.txtThe adjective Panada walked to the NOUN and then VERB. AnerbyNOUN was unaffected by these events.#!python3#-*- coding:utf-8 -*-#8.9.2疯狂填词游戏#用户自定义词语,修改打开文件中的ADJECTIVE、NOUN、VERBimport ref=open(‘first.txt‘,‘r+‘)files=f.read()print(files)f.close()changelist=[‘ADJECTIVE‘,‘NOUN‘,‘VERB‘]for i in changelist: change_reg=re.compile(r‘%s‘ % i) text=input("Enter a %s :" % i) files=change_reg.sub(text,files)fi_2=open(‘third.txt‘,‘w‘)fi_2.write(files)fi_2.close()"Python

Total Pages: 14 1 .... 10 11 12 13 14 Go to: Go

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.