• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

牛客编程题(十一)

互联网 diligentman 4周前 (01-31) 11次浏览

//https://www.nowcoder.com/practice/1e5655d7c7be4566b386eb925afcb206?tpId=185&tags=&title=&diffculty=0&judgeStatus=0&rp=1

import java.util.Arrays;
import java.util.Scanner;

public class Main4 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		System.out.println(change(s));
		
	}
	public static String change(String s) {
       char[] c = s.toCharArray();
       for(int i=0;i<c.length;i++) {
    	   c[i] = s.charAt(i);
       }
      String res = "";
       for(int i=0;i<c.length;i++) {
    	   if(c[i]=='a') {
    		   res = res.concat("a");
    	   }
       }
       String[]str = s.split("a");
       StringBuilder x1 = new StringBuilder();
       for(int i=0;i<str.length;i++) {
    	   x1.append(str[i]);
       }
       String x2 = x1.toString();
       StringBuilder x3 = new StringBuilder(x2);
       x3.append(res);
       return x3.toString();
    }

}

//https://www.nowcoder.com/practice/0ae4a12ab0a048ee900d1536a6e98315?tpId=125&&tqId=33732&rp=1&ru=/ta/exam-xiaomi&qru=/ta/exam-xiaomi/question-ranking

import java.util.Scanner;

public class Main5 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String xx = sc.nextLine();
		String[] str = xx.split(" ");
		for(int i=0;i<str.length/2;i++) {
			String temp = str[i];
			str[i]= str[str.length-i-1];
			str[str.length-i-1]=temp;
		}
		for(int i=0;i<str.length;i++) {
			if(i<str.length-1)
			System.out.print(str[i]+" ");
			else {
				System.out.println(str[i]);
			}
		}
	}
	 
	    

}

//https://www.nowcoder.com/practice/45083499b8c5404fb1db44c6ea4f170a?tpId=122&&tqId=33702&rp=1&ru=/ta/exam-wangyi&qru=/ta/exam-wangyi/question-ranking

import java.util.Scanner;

public class Main6 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();	
		char[] c= str.toCharArray();
		for(int i=0;i<c.length;i++) {
			c[i]=str.charAt(i);
		}
		String res ="";
		for(int i=0;i<c.length;i++) {
			if(c[i]==' ') {
				res=res.concat(String.valueOf(c[i+1]));
			}
		}
		res=String.valueOf(c[0]).concat(res);
		System.out.println(res);
	}

}

//https://www.nowcoder.com/practice/b178fcef3ed4448c99d7c0297312212d?tpId=125&tags=&title=&diffculty=0&judgeStatus=0&rp=1

import java.util.Scanner;

public class Main7 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println(climbStairs(n));
	}
	public static int climbStairs(int n) {
		if(n==1) {
			return 1;
		}
		if(n==2) {
			return 2;
		}
		if(n>=3) {
			return climbStairs(n-1)+climbStairs(n-2);
		}
		else
			return 0;
	}

}

//https://www.nowcoder.com/practice/e90351c561ff40a4b2bbf067bbbb5f31?tpId=128&&tqId=33791&rp=1&ru=/ta/exam-meituan&qru=/ta/exam-meituan/question-ranking

import java.util.Scanner;

public class Main8 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			if(n<m) {
				System.out.println(2);
			}
			else {
				int x1 = n*2/m;
				int x2 = n*2%m;
				System.out.println(x2==0?x1:x1+1);
			}
		
		}
	}
}

//https://www.nowcoder.com/practice/e297fdd8e9f543059b0b5f05f3a7f3b2?tpId=188&&tqId=36729&rp=1&ru=/ta/job-code-high-week&qru=/ta/job-code-high-week/question-ranking

import java.util.Scanner;
public class Main9 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
	System.out.println(judge(str));
		
	}
	 public static boolean judge (String str) {
	        // write code here
		if(str.equals(""))
			return true;
		str = str.toLowerCase();
		int start = 0;
		int end = str.length()-1;
		while(start<end) {
			while(!(str.charAt(start)>='a'&&str.charAt(start)<='z')||str.charAt(start)<='9'&&str.charAt(start)>='0') {
				start++;
			}
			while(!(str.charAt(end)>='a'&&str.charAt(end)<='z')||str.charAt(end)<='9'&&str.charAt(end)>='0') {
				end--;
			}
			if(str.charAt(start)!=str.charAt(end))
				return false;
				start++;
				end--;
		}
		return true;
			
			
	    }

}

//https://www.nowcoder.com/practice/8cc4f31432724b1f88201f7b721aa391?tpId=117&&tqId=35069&rp=1&ru=/ta/job-code-high&qru=/ta/job-code-high/question-ranking

import java.util.Arrays;

public class Main0 {
	public static void main(String[] args) {	
		int[]arr = {1,2,3,4};
		System.out.println(minNumberdisappered(arr));

		
	}
	 public static int minNumberdisappered (int[] arr) {
	        int res = 1;
	        Arrays.sort(arr);
	        while(true) {
	        	for(int i=0;i<arr.length;i++) {
	        		if(arr[i]!=res) {
	        			return res;
	        		}
	        		else
	        			res = res+1;
	        	}
	        }
	    }
}

//https://www.nowcoder.com/practice/05182d328eb848dda7fdd5e029a56da9?tpId=37&&tqId=21246&rp=1&ru=/ta/huawei&qru=/ta/huawei/question-ranking

import java.util.Scanner;

public class Main1 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String str = sc.nextLine();
			int min = 100;
			char[] c = str.toCharArray();
			StringBuilder ss = new StringBuilder();
			int[] sum = new int[str.length()];

			for (int i = 0; i < c.length; i++) {// 找到每个字符出现的次数
				for (int j = 0; j < str.length(); j++) {
					if (c[i] == str.charAt(j)) {
						sum[i]++;
					}
				}
			}

			for (int i = 0; i < sum.length; i++) {
				if (sum[i] < min) {
					min = sum[i];
				}
			}

			for (int i = 0; i < str.length(); i++) {
				if (sum[i] != min) {
					ss.append(str.charAt(i));
				}
			}
			System.out.println(ss);
		}
	}
}


程序员灯塔
转载请注明原文链接:牛客编程题(十一)
喜欢 (0)