package theArithmetic;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
public class Project {
/**
有些限制嫌麻烦就没写,到时如需要再补上
*/
/**
* 对任何一个正整数 n,如果它是偶数,那么把它砍掉一半;如果它是奇数,那么把 (3n+1) 砍掉一半。这样一直反复砍下去,
* 最后一定在某一步得到n=1。卡拉兹在 1950年的世界数学家大会上公布了这个猜想, 传说当时耶鲁大学师生齐动员,拼命想证明这个貌似很傻很天真的命题,
* 结果闹得学生们无心学业,一心只证 (3n+1),以至于有人说这是一个阴谋, 卡拉兹是在蓄意延缓美国数学界教学与科研的进展……
* 我们今天的题目不是证明卡拉兹猜想,而是对给定的任一不超过 1000 的正整数 n,简单地数一下, 需要多少步(砍几下)才能得到 n=1?
*/
static void theCallatz() {
int time = 0;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入需求数值");
String nextLine = scanner.nextLine();
int parseInt = Integer.parseInt(nextLine);
if (parseInt >= 0) {
int temp = parseInt;
while (temp > 1) {
if (temp % 2 == 0) {
temp = temp / 2;
} else {
temp = (temp * 3 + 1) / 2;
}
time++;
}
System.out.println(time);
}
}
/**
* 输入在第1行给出不超过10的5次方的正整数N,即参赛人数。 随后N行,每行给出一位参赛者的信息和成绩,包括其所代表的学校的编号(从1开始连续编号)、
* 及其比赛成绩(百分制),中间以空格分隔。
*
* 输出格式: 在一行中给出总得分最高的学校的编号、及其总分,中间以空格分隔。题目保证答案唯一,没有并列。 输入样例: 6 3 65 2 80 1 100 2
* 70 3 40 3 0
*
* 输出样例:
*
* 2 150
*/
static void theExcavatorTechnology() {
int totalNumber = 10 * 10 * 10 * 10 * 10;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入参赛人数");
String nextLine = scanner.nextLine();
int parseInt = Integer.parseInt(nextLine);
Map<Integer, Integer> hashMap = new HashMap<Integer, Integer>();
if (parseInt > 0) {
for (int i = 0; i < parseInt; i++) {
System.out.println("请输入学校编号以及成绩");
String nextLine1 = scanner.nextLine();
String[] split = nextLine1.split(" ");
if (hashMap.get(Integer.parseInt(split[0])) != null) {
int sc = (int) hashMap.get(Integer.parseInt(split[0])) + Integer.parseInt(split[1]);
hashMap.put(Integer.parseInt(split[0]), sc);
} else {
hashMap.put(Integer.parseInt(split[0]), Integer.parseInt(split[1]));
}
}
int tempSc = 0;
int tempSCor = 0;
for (Map.Entry<Integer, Integer> m : hashMap.entrySet()) {
if (m.getValue() > tempSCor) {
tempSCor = m.getValue();
tempSc = m.getKey();
}
}
System.out.println(tempSc + " " + tempSCor);
}
}
/**
* 查找元素 输入一个数n(1<=n<=200),然后输入n个数值各不相同的数,再输入一个值x,
* 输出这个值在这个数值中的下标(从0开始,若不在数组中则输出-1)。
*/
static void findX() {
boolean flag = false;
Scanner scanner = new Scanner(System.in);
System.out.println("请输入相关数组个数");
String nextLine = scanner.nextLine();
if (Integer.parseInt(nextLine) > 0) {
System.out.println("请输入相关数组 元素之间用空格隔开");
String nextLine1 = scanner.nextLine();
String[] split = nextLine1.split(" ");
if (nextLine1 != null || nextLine1 != "") {
System.out.println("请输入需要查找的x");
int nextLine2 = scanner.nextInt();
for (int i = 0; i < split.length; i++) {
if (Integer.parseInt(split[i]) == nextLine2) {
System.out.println(i+1);
flag = true;
}
}
}
if (!flag) {
System.out.println("-1");
}
}
}
public static void main(String[] args) {
// theCallatz();
// theExcavatorTechnology();
findX();
}
}