最难的问题_斐波那契凤尾_淘宝网店
最难的问题
// write your code here import java.util.*; public class Main{ public static void main(String[] args){ //密码字母:A B C D E F G H I J K L M N O P Q R S T U V W X Y Z //原文字母:V W X Y Z A B C D E F G H I J K L M N O P Q R S T U //输入密码 输出明文! //对照表: String table = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; Scanner sc = new Scanner(System.in); while(sc.hasNext()){ String str = sc.nextLine(); StringBuilder sb = new StringBuilder(); for(int i = 0;i<str.length();i++){ if(str.charAt(i)==' '){//空格直接保存! sb.append(' '); continue; } int index =(table.indexOf(str.charAt(i))-5+26)%26; //我们先找到这个密文在table的下标 - 5后得到明文位置下标, //有可能,下标会向前越界所以+26 最后%26反正向后越界! //我们就得到了对应明文的下标位置! sb.append(table.charAt(index)); } System.out.println(sb); } } }
斐波那契凤尾
// write your code here import java.util.*; public class Main{ public static int[] fib(){ int[] dp = new int[100001]; dp[1] = 1; dp[2] = 2; for(int i = 3;i<dp.length;i++){ dp[i] = (dp[i-1]+dp[i-2])%1000000; } return dp; } public static void main(String[] args){ Scanner sc = new Scanner(System.in); int[] array = fib(); while(sc.hasNext()){ int n = sc.nextInt(); //n = 25 斐波那契数大于1000000(100万) 需要前面补0! System.out.printf(n<25?"%d\n":"%06d\n",array[n]); } } }
淘宝网店
// write your code here import java.util.*; public class Main { private static boolean isLeapYear(int year) {//判断闰年! return year % 400 == 0 || (year % 4 == 0 && year % 100 != 0); } private static int profitOfYear(int year) {//计算一整年收入! return 2 * 31 + 1 * 28 + 1 * 31 + 2 * 30 + 1 * 31 + 2 * 30 + 1 * 31 + 2 * 31 + 2 * 30 + 2 * 31 + 1 * 30 + 2 * 31 +(isLeapYear(year) ? 1:0); } private static boolean isPrime(int month) {//判断是否为素数月! return month == 2 || month == 3 || month == 5 || month == 7 || month == 11; } private static int profitOfThisYear(int year,int month,int day){//计算从该年开始到这年的日期收入! int profit = 0; if(!isPrime(month)) { profit = day * 2; }else{ profit = day; } while(--month>0) { switch(month) { case 1:case 8:case 10:case 12: profit += 62; break; case 3:case 5:case 7: profit += 31; break; case 4:case 6:case 9: profit += 60; break; case 11: profit += 30; break; default: profit += (28+(isLeapYear(year)?1:0)); break; } } return profit; } public static void main(String[] args) { int year1,month1,day1,year2,month2,day2; int profit = 0; Scanner sc = new Scanner(System.in); while(sc.hasNext()) { year1 = sc.nextInt(); month1 = sc.nextInt(); day1 = sc.nextInt(); year2 = sc.nextInt(); month2 = sc.nextInt(); day2 = sc.nextInt(); // 计算开始这一年剩余时间的收入! //例如我们要计算 2011-3-15 ~ 2022-5-11收入! //我们可以 先计算2011年剩余时间收入;我们可以通过 2011整年收入 - 这一年到(2011-3-4)收入! // 加上 中间 2012~2021整年收入! // 加上 2022-5-11 这年收入! //计算 起始年份收入! profit = profitOfYear(year1) - profitOfThisYear(year1,month1,day1-1); //计算结束年份收入! profit += profitOfThisYear(year2,month2,day2); if(year1 == year2) {//如果这同一年! //上面的计算就是 起始时间到年末的收入 + 这一年到结尾时间的收入 //这里两个收入相交的收入就是 真正的收入 所以需要减去一整年的收入! profit -= profitOfYear(year1); } //计算中间整年收入! for(int i = year1+1;i<year2;i++) { profit += profitOfYear(i); } System.out.println(profit); } } }#笔试##腾讯##京东#