华为机试题记录1

import java.math.BigInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.*;
public class Main {
	
	public static void main(String args[]){
		
		//isSameTree();
		//selectSeven();
		//namePretty();
		//treeBehind();
		//nikechesi();
		//recoverTree();
		//biggestScore();
		//songQuene1();
		//printDiffChar();
		//bigInt();
		//gdc();
		//zeroCount();
		//picsort();
		//delLeast();
		//bottle();
		//test();
		//move();
		//arraySort();
		//money();
		//separated();
		//change();
		//card();
		
		//findMoney();
		wordSort()	;
	}

	
	public static void isSameTree(){
		
		Scanner s= new Scanner(System.in);
		//判断个数
		int num = Integer.valueOf(s.nextLine());
		//第一个序列
		String firstTreeStr = s.nextLine();
		//得到第一个序列的两个子串,第一个子串全部小于串中第一个数字,第二个子串全部大于第一个数字,顺序和原串相同
		
		String subFirstTreeStrSmall = devideTree( firstTreeStr,1);
		String subFirstTreeStrBig = devideTree( firstTreeStr,2);
		
//		System.out.println(subFirstTreeStrSmall);
//		System.out.println(subFirstTreeStrBig);
		String treeStr = s.nextLine();
		String subTreeStrSmall = devideTree( treeStr,1);
		String subTreeStrBig = devideTree( treeStr,2);
		
		ArrayList res = new ArrayList();
		
		while(!treeStr.equals("0")){
			
			if(subTreeStrSmall.equals(subFirstTreeStrSmall)&&subTreeStrBig.equals(subFirstTreeStrBig))
				 res.add("YES");
				 //System.out.println("YES");
			 else res.add("NO");//System.out.println("NO");
			
			
			 treeStr = s.nextLine();
			 subTreeStrSmall = devideTree( treeStr,1);
			 subTreeStrBig = devideTree( treeStr,2);
		}
		
		for(int i=0;ifirstStr)
					subStr+=nextStr;
				
				
			}
		}
		
		
		
		return subStr;
		
	}
	
	//挑7
	public static void selectSeven(){
		
		Scanner s = new Scanner(System.in);
		
		int num = s.nextInt();
		
		int count=0;
		
		for(int i = 1;i hm = new HashMap();
		ArrayList list = new ArrayList();
		String resStr = "";
		while(sum!=num){
			hm.clear();
			list.clear();
			String name = s.nextLine();
			
			for(int i = 0;i=100){
			System.out.println("-1");
			return;
		}
		int i =0,j=0;
		for(i=(num*(num-1)+1);j=stuNum) b--;//控制越界
					for(int j = b;j<=c;j++){
						
						if(Integer.valueOf(scoreArray[j])>big){
							
							big = Integer.valueOf(scoreArray[j]);
							
						}
					}
					//res+=big+"\n";
					
					System.out.println(big);
					
				}else if(a.equals("U")){
					
					scoreArray[b]=String.valueOf(c);
					
					
				}
			}
			
			//System.out.print(res);
		
			
		}
		//合唱队
		public static void songQuene(){
			
			Scanner n = new Scanner(System.in);
			
			int num = Integer.valueOf(n.nextLine());
			String high = n.nextLine();
			
			String [] highArray = high.split(" ");
			
			int a[] = new int[num];
			int b[] = new int[num];
			
			for(int i=0;iInteger.valueOf(highArray[j]))
						a[i]+=1;
				}
			}
			
			for(int i=0;iInteger.valueOf(highArray[j]))
						b[i]+=1;
				}
			}
			int res=0;
			for(int i=0;ires)
				
				res=a[i]+b[i];
				
			}
			
			System.out.println(res);
		}
		
		//合唱队
				public static void songQuene1(){
					
					Scanner n = new Scanner(System.in);
					
					int num = Integer.valueOf(n.nextLine());
					String high = n.nextLine();
					
					String [] highArray = high.split(" ");
					
					int a[] = new int[num];
					int b[] = new int[num];
					
					for(int i=0;iInteger.valueOf(highArray[j])&&(a[i]-1;i--){
						b[i]=1;
						for(int j = num-1;j>i;j--){					
							if(Integer.valueOf(highArray[i])>Integer.valueOf(highArray[j])&&(b[i]res)
						
						res=a[i]+b[i]-1;
						System.out.println(a[i]+"   " +b[i]+"   " +highArray[i]);
						
					}
					
					System.out.println(num-res);
				}
				
				
				//将字符串中不同字符的个数打印出来
				public static void printDiffChar() {
					
					Scanner n = new Scanner(System.in);
					
					String str = n.nextLine();
					
					
					ArrayList list = new ArrayList();
					
					for(int i=0;ib
					int  temp=0;
					if(a>1;
					}
					
					//System.out.println("count="+count+"    pos"+pos);
					int result=count-(32-(pos+1));
					System.out.println(result);
				}
				
				//图片整理
				public static void picsort(){
					
					Scanner n = new Scanner(System.in);
					String s = n.nextLine();
					
					char[] c=s.toCharArray();
					
					Arrays.sort(c);
					
					for(int i=0;imin) System.out.print(c);
					}
					
					
				}
				
				//汽水瓶
				public static void bottle(){
					
					Scanner sn = new Scanner(System.in);
					
					int n=sn.nextInt();
					while(n!=0){
						int count=0;
						int b=0;int c=0;
						while(n>1){
							
							if(n==2) {
								count+=1;
								break;								
							}
							else{
								b=n/3;
								c=n%3;
								count+=b;
								n=b+c;
							}
						}
						
						System.out.println(count);
						n=sn.nextInt();
					}
					
					
					
				}
				
				public static void test(){
					
					Scanner n=new Scanner(System.in);
					while(n.hasNext()){
					
					int str = n.nextInt();
					
					
					//System.out.println(str.replaceAll("a",""));
					System.out.println(str);
					}
					
				}
				
				//坐标移动
				public static void move(){
					
					Scanner n=new Scanner(System.in);
					
					String str = n.nextLine();
					
					String array[] = str.split(";");
					
					int x=0;int y=0;
					
					for(int i=0;i=48&&sec1<=57&&sec2>=48&&sec2<=57){
							if(sec1>=48&&sec1<=57&&sec2>=48&&sec2<=57&&firS.equals("A")||firS.equals("D")||firS.equals("S")||firS.equals("W")){
								//System.out.println("-----------"+secS);
								if(firS.equals("A")){
									x-=Integer.parseInt(secS);									
								}else if(firS.equals("D")){
									x+=Integer.parseInt(secS);									
								}else if(firS.equals("W")){
									y+=Integer.parseInt(secS);									
								}else if(firS.equals("S")){																		
									y-=Integer.parseInt(secS);									
								}
							}
						}
						
					}
					System.out.println(x+","+y);
					
					
				}
				
				//整数排序
				public static void arraySort(){
					
					Scanner n = new Scanner(System.in);
					String str = n.nextLine();
					
					String array[] = str.split(",");
					//需要把字符型数组转成整形数组
					int iarray[] = new int[array.length];
					
					
					
					for(int x=0;x250)
				         {
				            continue;
				         }    
				         for(a=0;a<=n/100;a++)
				         for(b=0;b<=n/50;b++)
				         for(c=0;c<=n/20;c++)
				            for(d=0;d<=n/10;d++)
				             for(e=0;e<=n/5;e++)
				             for(f=0;f<=n/2;f++)
				             for(g=0;g<=n;g++)
				             {
				                    if( (n==a*100+b*50+c*20+d*10+e*5+f*2+g) && (a+b+c+d+e+f+g<=100) )
				                    {
				                        s++;    
				                        break;
				                    }

				             }
				         System.out.println(s);
				         n=sn.nextInt();
				     }
			        

					
				}
				
				//整数分隔
				public static void separated(){
					
					Scanner n = new Scanner(System.in);
					
					while(true){
						
						int num = n.nextInt();
						
						if(num>=1&&num<=1000000)
						
						System.out.println(ff(num)%1000000000);
						else System.out.println(-1);
					}
				}
				//这个方法栈溢出
				public static int f(int n){
					
					int result=0;
					if(n==1) result=1;
					else if(n%2==0) result=(f(n-1)+f(n/2))%1000000000;
					else if(n%2==1) result=(f(n-1))%1000000000;
					
					return result;
				}
				
				//利用数组存放所有结果
				public static int ff(int n){
					
					int result[]=new int[1000001];
					
					for(int i=1;i<1000001;i++){
						result[1]=1;
						if(i%2==0) result[i]=(result[i-1]+result[i/2])%1000000000;
						else if(i%2==1) result[i]=(result[i-1])%1000000000;
						
						
							
					}
					
					return result[n];
				}
				
				//字符转换
				public static void change(){
					
					Scanner n = new Scanner(System.in);
					
					String str = n.nextLine();
					
					for(int i=0;i=65&&x<=85) s=String.valueOf((char)(x+37));
						if(x>=86&&x<=90) s=String.valueOf((char)(x+11));
						
						System.out.print(s);
						
					}
					
					
					
				}
				
				//扑克牌大小
				public static void card(){
					
					Scanner n = new Scanner(System.in);
					
					String str = n.nextLine();
					
					int index = str.indexOf("-");

					String aa[] = str.substring(0,index).split(" ");
					String bb[] = str.substring(index+1,str.length()).split(" ");
					
					int a[] = changeCard(aa);
					int b[] = changeCard(bb);
					
					
					int al = a.length;
					int bl=b.length;
					
					if(al==2){
						if(a[0]==16||a[0]==17){
							System.out.println(str(aa));
							return;
						}else if(bl==4){							
							System.out.println(str(bb));
							return;
						}else if(bl==2){
							
							if(a[0]>b[0]) System.out.println(str(aa));
							else if(a[0]b[0]) System.out.println(str(aa));
							else if(a[0]b[0]) System.out.println(str(aa));
						else if(a[0] list = new ArrayList();
						
						char[] strArray = str.toCharArray();
						
						for(int i=0;i='a'&&strArray[i]<='z')||(strArray[i]>='A'&&strArray[i]<='Z')){
								
								list.add(strArray[i]);
								strArray[i]='\0';								
							}
							
							
						}
						
						Collections.sort(list);
						System.out.println(list);
						int j=0;
						String result="";
						for(int i=0;i

你可能感兴趣的:(LeetCode)