Huawei School recruit Hangxia Programming topic

Source: Internet
Author: User

Topic one           input two strings, output matching number of times, such as  AAAAC and AA  output 2

I didn't think of this water, the regular expression can also be import java.util.scanner;import Java.util.regex.matcher;import Java.util.regex.pattern;public class  main{public static void Main (string[] args) {Scanner sc=new Scanner (system.in); String S1; String s2;int Count=0;while (Sc.hasnext ()) {count=0;s1=sc.next (); S2=sc.next (); Matcher matcher=pattern.compile (S2). Matcher (S1); while (Matcher.find ()) {count++;} System.out.println (count);}}}


Topic two     has a list of comma-separated numbers, sorted output, output requirements, sequential output only the beginning and end of the number, all other cases output

Import Java.util.arraylist;import java.util.collections;import Java.util.list;import Java.util.Scanner;public class Copyofcopyofmain {public static void main (string[] args) {Scanner sc = new Scanner (system.in); String S1;while (Sc.hasnext ()) {S1 = Sc.next (); string[] Nums = S1.split (","); list<integer> list = new arraylist<> (); for (string string:nums) {List.add (Integer.parseint (String));} if (list.size () = = 1) {System.out.println (list.get (0)); continue;} Collections.sort (list); System.out.print (list.get (0)); for (int i = 1; i < List.size ()-1; i++) {if (List.get (i)-list.get (i-1) = = 1    &am p;&    List.get (i + 1)-list.get (i) = = 1) {} else {System.out.print (""); System.out.print (List.get (i));}} System.out.println ("" + List.get (List.size ()-1);}}}

Topic Three        

This problem is the most water, Java a sentence to fix, C + + words can only realize the import Java.math.BigInteger; Import Java.util.scanner;public class Copyofcopyofmain {public static void main (string[] args) {Scanner sc = new Scanner (S ystem.in); String S1;while (Sc.hasnext ()) {S1 = Sc.nextline (); String nums[]=s1.split ("+"); System.out.println (New BigInteger (Nums[1]). Subtract (new BigInteger (Nums[0]));}}}


Half an hour all done, once through



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Huawei School recruit Hangxia Programming topic

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.