One. Algorithm:
1, the definition of the algorithm:
An algorithm is a description of the solution steps for a particular problem, represented in the computer as an ordered sequence of instructions, and each instruction represents one or more operations. The algorithm is the method that describes the problem. (A number of algorithms can be resolved for a given problem)
2. Algorithms
01: One-size-fits-all (post-correction)
String // result a,b,c,d,e,f,g string result= ""; for (int i=0;i<b.length (); i++) { result+ = "," +b.charat (i); get each character //, A,b,c,d,e,f,g } Result= Result.substring (1); SYSTEM.OUT.PRINTLN (result);
02. Common API for strings (hypothesis correction method)
String b= "ABCDEFGABCD";//asks if there are duplicate characters in the string Booleanflag=false;//suppose not to repeat for(intI=0;i<b.length (); i++){ CharC=b.charat (i);//get every character if(B.lastindexof (c)! =i) {Flag=true;//RepeatSystem.out.println ("Repeat"); Break; } System.out.println ("Do not repeat"); }
03. Common API for strings (regular Expressions) ReplaceAll ()
// inside the parentheses we call the subgroup, and we get the sub-group content. String a= "Asasasa 2018-07-16 Sasa Sasas sasa"; // the effect is Asasasa 07/16/2018 Sasa Sasas SasaA=a.replaceall ("([0-9]{4})-([0-9]{2})-([0-9]{2})", "$2/$3/$1 Year" ); System.out.print (a);
Note: Regular expressions commonly used in two classes
Pattern
01: Represents the regular expression itself
02: Preprocessing The regular expressions we write
03: Improve the running efficiency of our Code
Matcher
01: Represents the calculation result of the regular expression
02: The implementation of the regular complex operation
04. Determine if a string satisfies the regular expression we define
String a= "ABC01234"; A.matches (// return Boolean
05. Chicken and Rabbit cage
/* a total of 50 chickens and a total of 120 feet! x+y=50; 2x+4y=120; */ for (int x=0;x<=50;x++) { int// get the number of rabbits if( 2*x+4*y==120) { System.out.println (x); System.out.println (y); } }
06. Enumeration and Pruning change
/*demand: Find 50 yuan Now some currency is: 10 yuan 5.5 yuan 100 50 5 Find out all the change plan! */ intmoney=500; for(intA = 0; a <=money/100; a++) {// - for(intb = 0; b <=money/50; b++) {// - if((500-(A*100+B*50) <0)) Break;//Pruning intc = (500-(a*100+b*50))/5;//5 if(a*100+b*50+c*5==500) {System.out.println ("10 yuan of the number of occurrences =" "+a+" \t5 yuan the number of occurrences = "+b+" \t5 corner money occurrences = "+c); } } }
07. Enumeration and pruning to find the number of digits
/* demand: The mantissa of the number itself squared = itself (within 100W) 0 0 1 1 5 6 + 625 * /for (int a = 0; a <=1000000; a++) {// ask for the square of a int num=a*A; if (num%10==a| | num%100==a| | num%1000==a| | num%10000==a| | num%100000==a| | num%1000000==a) { System.out.println ("the number itself =" "+a+" the square of the number is = "+num);} }
08. Conversion of strings and numbers
// The string needs to be converted into a digital 6789 int result=0; for (int i = 0; I <str.length (); i++) { result=result*10+str.charat (i)-' 0 '; } SYSTEM.OUT.PRINTLN (result);
09. Conversion between arbitrary binaries
String num= "200110102";//3 binary numbers converted to 5 binary intResult=0; for(inti = 0; I <num.length (); i++) { CharC=Num.charat (i); Result=result*3+ (c ' 0 '); //result=0 + (50-48) = 2//result=2*3 + (48-48) = 6//result=6*3 + (48-48) =//result=18*3 + (49-48) =//result=55*3 + (49-48) = 166//result=166*3 + (48-48) = 498//result=498*3 + (49-48) = 1495//result=1495*3 + (48-48) = 4485//result=4485*3 + (50-48) = 13457} System.out.println (Result); //decimal 13457String str= ""; while(true){ if(result==0) Break; STR+=result%5; Result=result/5; } System.out.println (str); }
program------> Algorithms