华为机试
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int in = scanner.nextInt();
String str = String.valueOf(in);
for (int i = str.length()-1; i >=0 ; i--) {
System.out.print(str.charAt(i));
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
for (int i = str.length()-1; i >=0 ; i--) {
System.out.print(str.charAt(i));
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (scanner.hasNext()){
int n = scanner.nextInt();
if (n == 0) {
break;
}
System.out.println(n/2);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n=sc.nextInt();
if (n == 0) {
break;
}
int count=0;
int tmp;
while(n>=2){
count+=n/3;
tmp=n%3;
n=n/3+tmp;
if(n==2){
count++;
break;
}
}
System.out.println(count);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
System.out.println(reversestr(str));
}
public static String reversestr(String str){
String[] splitstr = str.split("[^a-zA-Z]");
StringBuffer reversestr = new StringBuffer();
for(int i=splitstr.length-1;i>=0;i--){
reversestr.append(splitstr[i]).append(" ");
}
str = reversestr.toString().trim();
return str;
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
String str = in.nextLine();
char[] chars = str.toCharArray();
for(int i=chars.length-1;i>=0;i--){
System.out.print(chars[i]);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int num=sc.nextInt();
printtriangle(num);
}
}
public static void printtriangle(int num){
int y=1;
int yCount=1;
for(int i=1;i<=num;i++){
int x=y;
int xCount=i+1;
for(int j=1;j<=num-i+1;j++){
System.out.print(x+" ");
x+=xCount++;
}
System.out.println("");
y+=yCount++;
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int num=sc.nextInt();
System.out.println(test(num));
}
}
public static int test(int num){
if (num == 1 || num == 2) {
return 1;
}
return test(num-1)+test(num-2);
}
}
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
while(sc.hasNext()){
int num=sc.nextInt();
System.out.println(test(num));
}
}
public static int test(int n){
return (1 + 3*n) * n / 2;
}
}
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
System.out.println(a*b/gcd(a,b));
}
public static int gcd(int a,int b){
if (b == 0) {
return a;
}
return gcd(b,a%b);
}
}
import java.util.Scanner;
public class Main {
public static void main(String args[]){
Scanner sc=new Scanner(System.in);
while (sc.hasNext()){
int m=sc.nextInt();
int n=sc.nextInt();
if (n >= 1 && n <= 10 && m >= 1 && m <= 10) {
System.out.println(count(m, n));
}
}
}
public static int count(int m,int n){
if(m<0||n<=0)
return 0;
if(m==1||n==1||m==0)
return 1;
return count(m,n-1)+count(m-n,n);
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
String[] arr = str.split(" ");
int a = Integer.parseInt(arr[0]);
int b = Integer.parseInt(arr[1]);
int c = Integer.parseInt(arr[2]);
int[] month = {31,28,31,30,31,30,31,31,30,31,30,31};
int count = 0;
for(int i=0;i<b-1;i++){
count+=month[i];
}
count+=c;
if(b>2 && (a%4==0&&a%100!=0 || a%400 ==0)){
count++;
}
System.out.println(count);
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
List<String> list = getListStr(str);
int maxLen = 0;
for (String obj: list) {
StringBuffer temp = new StringBuffer(obj);
if(obj.equals(temp.reverse().toString())){
if(maxLen < obj.length()){
maxLen = obj.length();
}
}
}
System.out.println(maxLen);
}
private static List<String> getListStr(String str) {
List<String> list = new ArrayList<>();
for (int i = 0; i < str.length(); i++) {
for (int j = i+1; j <= str.length(); j++) {
list.add(str.substring(i,j));
}
}
return list;
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
String stra = sc.nextLine();
String strb = sc.nextLine();
List<String> lista = getListStr(stra);
List<String> listb = getListStr(strb);
int maxLen = 0;
for (String obja: lista) {
for (String objb: listb){
if(obja.equals(objb)){
if(maxLen < objb.length()){
maxLen = objb.length();
}
}
}
}
System.out.println(maxLen);
}
private static List<String> getListStr(String str) {
List<String> list = new ArrayList<>();
for (int i = 0; i < str.length(); i++) {
for (int j = i+1; j <= str.length(); j++) {
list.add(str.substring(i,j));
}
}
return list;
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
String str = sc.nextLine();
int len= str.replaceAll("[^A-Z]","").length();
System.out.println(len);
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
int n = sc.nextInt();
int b = n*(n-1)+1;
for (int i = 0; i < n; i++) {
if (i != n-1) {
System.out.print(b+2*i+"+");
}else {
System.out.println(b+2*i);
}
}
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
int n = sc.nextInt();
int countA = 0;
int countB = 0;
int temp = 0;
double ave;
for (int i = 0; i < n; i++) {
int b = sc.nextInt();
if (b < 0) {
countA ++;
}else if (b > 0) {
countB ++;
temp += b;
}
}
ave = (double) temp/(double) countB;
System.out.println(countA+" "+String.format("%.1f", ave));
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNextInt()){
int n = in.nextInt();
int count = 0;
for(int i=1; i <= n; i++){
int sum = 0;
for(int j=1; j <= i/2; j++){
if(i%j == 0)
sum += j;
}
if(sum == i)
count++;
}
System.out.println(count);
}
}
}
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
while(in.hasNextInt()){
int n = in.nextInt();
int a = 0,b = 0,c = 0;
for (a = 0; a <= 20; a++) {
for (b = 0; b <=33 ; b++) {
for (c = 0; c < 100; c++) {
if (c%3 ==0 && 5*a+3*b+c/3 == 100 && a+b+c == 100) {
System.out.println(a+" "+b+" "+c);
}
}
}
}
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNextInt()) {
int m = sc.nextInt();
int n = sc.nextInt();
System.out.println(cal(m,n));
}
}
private static int cal(int m,int n){
if(m==1 || n== 1){
return m+n;
}
return cal(m-1,n)+cal(m,n-1);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
for(int i=n/2;i>=2;i--){
if(isPrime(i)&&isPrime(n-i)){
System.out.println(i);
System.out.println(n-i);
break;
}
}
}
}
public static boolean isPrime(int n){
for(int i =2;i<n;i++){
if(n%i==0){
return false;
}
}
return true;
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()){
int n = sc.nextInt();
String binaryStr = Integer.toBinaryString(n);
String[] strArray = binaryStr.split("0");
int result = 0;
for (int i = 0; i < strArray.length; i++) {
if (strArray[i].length() > result) {
result = strArray[i].length();
}
}
System.out.println(result);
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while (sc.hasNext()){
int num = sc.nextInt();
if(num == 1 || num == 2){
System.out.println(-1);
}else {
if(num % 2==1){
System.out.println(2);
}else if(num %4 == 2){
System.out.println(4);
}else {
System.out.println(3);
}
}
}
}
}
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str = sc.nextLine();
StringBuilder stringBuilder = new StringBuilder();
List<String> arrayList = new ArrayList<>();
boolean flag = false;
for (int i = 0; i < str.length(); i++) {
char c = str.charAt(i);
if (String.valueOf(c).equals("\"")) {
flag = !flag;
continue;
}
if (String.valueOf(c).equals(" ") && !flag) {
arrayList.add(stringBuilder.toString());
stringBuilder = new StringBuilder();
} else {
stringBuilder.append(c);
}
}
arrayList.add(stringBuilder.toString());
System.out.println(arrayList.size());
for (String s : arrayList) {
System.out.println(s);
}
}
}
import java.util.*;
public class Main{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
String s=sc.nextLine();
s=s.replace("{","(");
s=s.replace("[","(");
s=s.replace("}",")");
s=s.replace("]",")");
System.out.println(slove(s));
}
public static int slove(String s){
Stack<Integer> stack=new Stack<>();
int n=s.length();
char[] chs=s.toCharArray();
char sign='+';
int number=0;
for(int i=0;i<n;i++){
char ch=chs[i];
if(ch==' ')continue;
if(Character.isDigit(ch)){
number=number*10+ch-'0';
}
if(ch=='('){
int j=i+1;
int count=1;
while(count>0){
if(chs[j]==')')count--;
if(chs[j]=='(')count++;
j++;
}
number=slove(s.substring(i+1,j-1));
i=j-1;
}
if(!Character.isDigit(ch) || i==n-1){
if(sign=='+'){
stack.push(number);
}
else if(sign=='-'){
stack.push(-1*number);
}
else if(sign=='*'){
stack.push(stack.pop()*number);
}
else if(sign=='/'){
stack.push(stack.pop()/number);
}
sign=ch;
number=0;
}
}
int ans=0;
while(!stack.isEmpty()){
ans+=stack.pop();
}
return ans;
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
while(sc.hasNext()) {
int m = sc.nextInt();
int n = sc.nextInt();
int x1 = sc.nextInt();
int y1 = sc.nextInt();
int x2 = sc.nextInt();
int y2 = sc.nextInt();
int x = sc.nextInt();
int y = sc.nextInt();
int a = sc.nextInt();
int b = sc.nextInt();
if (m<=9 && n<=9) {
System.out.println(0);
}else {
System.out.println(-1);
}
if (x1<m && x2<m && y1<n && y2<n) {
System.out.println(0);
}else {
System.out.println(-1);
}
if (x<m && m<9) {
System.out.println(0);
}else {
System.out.println(-1);
}
if (y<n && n<9) {
System.out.println(0);
}else {
System.out.println(-1);
}
if (a<m && b<n) {
System.out.println(0);
}else {
System.out.println(-1);
}
}
}
}
import java.util.LinkedHashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
int n = in.nextInt();
String[] names = new String[n];
LinkedHashMap<String, Integer> map = new LinkedHashMap<>();
for (int i = 0; i < n; i++) {
names[i] = in.next();
map.put(names[i], 0);
}
int num = in.nextInt();
String[] votes = new String[num];
for (int i = 0; i < num; i++) {
votes[i] = in.next();
}
for (int i = 0; i < num; i++) {
for (int j = 0; j < n; j++) {
if (names[j].equals(votes[i])) {
map.put(names[j], map.get(names[j]) + 1);
}
}
}
int value = 0;
for (String str : map.keySet()) {
System.out.println(str + " : " + map.get(str));
value = value + map.get(str);
}
System.out.println("Invalid : " + (num - value));
}
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
double num = sc.nextDouble();
double x = Dichotomy(num);
System.out.printf("%.1f", x);
}
public static double Dichotomy(double num) {
double right, left, mid;
right = Math.max(1.0, num);
left = Math.min(-1.0, num);
while (right - left > 0.0000001) {
mid = (left + right) / 2;
if (mid * mid * mid > num) {
right = mid;
}
else if (mid * mid * mid < num) {
left = mid;
} else {
return mid;
}
}
return right;
}
}
import java.util.*;
public class Solution {
public static void main(String[] args) {
int[] a = {10, 2,8,66,54,10};
Solution solution = new Solution();
System.out.println(solution.test(a));
}
public String test(int[] a){
StringBuilder sb = new StringBuilder();
for (int j : a) {
sb.append(j);
}
String str = sb.toString();
List<Integer> list = new ArrayList<>();
for (int i = 0; i < str.length(); i++) {
int c = Character.getNumericValue(str.charAt(i));
list.add(c);
}
Collections.sort(list);
StringBuilder stringBuilder = new StringBuilder();
for (Integer integer : list) {
stringBuilder.append(integer);
}
return stringBuilder.reverse().toString();
}
}