牛客编程题(十二)

//https://www.nowcoder.com/practice/ddbfc06b8c06403687f8e8ff4d57d5ad?tpId=185&&tqId=35109&rp=1&ru=/ta/weeklycontest-history&qru=/ta/weeklycontest-history/question-ranking

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

public class Main2 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int xx = sc.nextInt();

	}

	public static boolean solve(int x) {
		for (int i = 0; i < 1000; i++) {
			if (i * i % 1000 == x)
				return true;
		}
		return false;
	}
}

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

import java.util.Arrays;

public class Main3 {
	public static void main(String[] args) {

	}

	public static int Answerofjudge(int[] arr) {
		// write code here
		Arrays.sort(arr);
		double res = 0.0;
		for (int i = 0; i < arr.length; i++) {
			res += arr[i];
		}
		double average = res / (arr.length);
		double mid = 0;
		if (arr.length % 2 != 0) {
			mid = arr[arr.length / 2];
		} else {
			mid = (arr[arr.length / 2] + arr[arr.length / 2 - 1]) / 2.0;
		}

		if (mid < average)
			return -1;
		if (mid == average)
			return 0;
		else
			return 1;
	}
}

//https://www.nowcoder.com/practice/c4ea1f2263434861aef111aa44a5b064?tpId=140&&tqId=33905&rp=1&ru=/ta/exam-iqiyi&qru=/ta/exam-iqiyi/question-ranking

import java.util.Scanner;

public class Main5 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.next();
		System.out.println(removeRepetition(str));
		
	}
	public static String removeRepetition(String str) {
		String str1 = "";//定义一个空串
		for(int i=0;i<str.length();i++) {
			char c = str.charAt(i);//将字符串拆成字符赋值给c
			if(str.indexOf(c)==i) {//如果字符串没有重复,即:每个字符的下标都会等价于该字符第一	次出现时的下标
  									//判断字符串第一次出现c字符时的下标是否等于i
				str1 = str1.concat(String.valueOf(c));//进行拼接
			}
		}
		return str1;
	}

}

//https://www.nowcoder.com/practice/91a588dd4cd244bfa616f17603ec123c?tpId=107&&tqId=33328&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking

import java.util.Scanner;

public class Main6 {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			String s = sc.next();
			char c = s.charAt(0);
			if((c>='a'&&c<='z') ||c>='A'&&c<='Z'){
				System.out.println(c+" is an alphabet.");
			}
			else
				System.out.println(c+" is not an alphabet.");
		}

	}

}

//https://www.nowcoder.com/practice/b8f770674ba7468bb0a0efcc2aa3a239?tpId=107&&tqId=33336&rp=1&ru=/ta/beginner-programmers&qru=/ta/beginner-programmers/question-ranking

import java.util.Scanner;

public class Main7 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String x = sc.next();
		char[] c1 = x.toCharArray();
		for(int i=0;i<c1.length;i++) {
			c1[i]=x.charAt(i);
		}
		
		Integer x1 = Integer.parseInt(x.charAt(0) + "");
		char c = x.charAt(1);
		Integer x3 = Integer.parseInt(x.charAt(2) + "");
		if (c == '+') {
			System.out.println(String.format("%.4f+%.4f=%.4f", x1, x3, (x1+x3)));
		} else if (c == '-') {
			System.out.println(String.format("%.4f-%.4f=%.4f", x1, x3, (x1-x3)));
		} else if (c == '/') {
			if (x3 == '0') {
				System.out.println("Wrong!Division by zero!");
			} else {
				System.out.println(String.format("%.4f/%.4f=%.4f", x1, x3, (x1 / x3)));
			}

		} else if (c == '*') {
			System.out.println(String.format("%.4f*%.4f=%.4f", x1, x3, (x1 * x3)));
		} else
			System.out.println("Invalid operation!");
	}

}

//https://www.nowcoder.com/practice/02cb8d3597cf416d9f6ae1b9ddc4fde3?tpId=37&tags=&title=&diffculty=0&judgeStatus=0&rp=1

94

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

public class Main8 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			int x = sc.nextInt();//键盘录入一个数字作为创建数组的长度大小
			String[] str = new String[x];//创建String数组
			for (int i = 0; i < str.length; i++) {
				str[i] = sc.next();//for循环,键盘录入字符串
			}
			for (int i = 0; i < str.length; i++) {
				int[] count = new int[26];//定义一个26个长度大小的数组
				int len = str[i].length();//获取每个输入字符串长度
				for (int j = 0; j < len; j++) {
					char asc = str[i].charAt(j);//获取每一个字符
					if (asc >= 'a' && asc <= 'z') {//判断字符是否属于26个英文字母,如果是的话,就给count数组对应位置加一
						count[asc - 97]++;
					} else if (asc >= 'A' && asc < 'Z') {
						count[asc - 65]++;
					}
				}
				Arrays.sort(count);//对count数组排序
				int beauty = 0;
				for(int k=0;k<26;k++) {
					beauty+=count[k]*(k+1);//这个的意思是,上面排好的顺序,出现最多的,在count数组中记录的是次数,也就是让其对应乘以26,这样即可保证输出最大的漂亮度
				}
				System.out.println(beauty);
			}
		
			
		}
	}

}

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

95

import java.util.Scanner;

public class Main9 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (sc.hasNext()) {
			String str = sc.next();
			int len = sc.nextInt();
			StringBuilder xx = new StringBuilder();
			
			// 解法一:char[]c = new char[len];
			// for(int i=0;i<c.length;i++) {
			// c[i]=str.charAt(i);
			// xx.append(c[i]);
			// }
			//解法二:
			for (int i = 0; i < len; i++) {
				xx.append(str.charAt(i));
			}

			System.out.println(xx.toString());
		}

	}

}

//https://www.nowcoder.com/practice/2f6f9339d151410583459847ecc98446?tpId=37&tags=&title=&diffculty=0&judgeStatus=0&rp=1

96

import java.util.Scanner;

public class Main0 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		double hight = sc.nextInt();
		double res = hight;
		for (int i = 0; i < 4; i++) {
			res+=hight;
			hight/=2.0;
		}
		hight/=2.0;
		System.out.println(res);
		System.out.println(hight);
	}

}
  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值