catalogue
1. Taobao online store
Link: Taobao online store__ Niuke.com
Source: niuke.com
[programming question] Taobao online store
- Heat index: 1556 time limit: C/C++ 1 second, other languages 2 seconds space limit: C/C++ 32M, other languages 64M
- Video Explanation of algorithm knowledge
NowCoder opened an online shop on Taobao. He found that when the month was prime, he could earn 1 yuan a day that month; Otherwise, you can earn 2 yuan a day.
Now let's give you a period of time. Please help him calculate the total income.
Enter Description:
The input contains multiple sets of data. Each group of data contains two dates from and to (2000-01-01 ≤ from ≤ to ≤ 2999-12-31). The date is represented by three positive integers separated by spaces: year month day.
Output Description:
For each set of data, output how much money you can earn within a given date range (including start and end dates).
Example 1
input
2000 1 1 2000 1 31 2000 2 1 2000 2 29
output
62 29
- All codes
// write your code here import java.util.*; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int year1 = sc.nextInt(); int month1 = sc.nextInt(); int day1 = sc.nextInt(); int year2 = sc.nextInt(); int month2 = sc.nextInt(); int day2 = sc.nextInt(); int money = 0; if(year2-year1 == 0){ for(int i = month1;i <= month2;i++){ int x = primeMonth(i); if(month1 == month2) { money += (day2-day1+1) * x; } else { if (i == month1) { //When is the first month money += (getDaysByMonth(year1, month1) - day1 + 1) * x; } else if (i == month2) { //When it's the last month money += (day2) * x; } else { //Intermediate month if (i > month1 && i < month2) { money += getDaysByMonth(year1, i) * x; } } } } }else{ //Different years for (int i = month1; i <= 12; i++) {//First year int x = primeMonth(i); if (i == month1) { money += (getDaysByMonth(year1, month1) - day1 + 1) * x; } else { money += getDaysByMonth(year1, i) * x; } } if (year2 - year1 > 1) { int tmp = year1 + 1; while (tmp < year2) { for (int i = 1; i <= 12; i++) { int x = primeMonth(i); money += getDaysByMonth(tmp, i)*x; } tmp++; } } for (int i = 1; i < month2; i++) {//Last year int x = primeMonth(i); money += getDaysByMonth(year2, i) * x; } int x = primeMonth(month2); money += day2*x; } System.out.println(money); } } public static int getDaysByMonth(int year,int month) { if (month == 2) { if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) { return 29; } else { return 28; } } else if (month == 4 || month == 6 || month == 9 || month == 11) { return 30; } else { return 31; } } public static int primeMonth(int month){ if(month == 2 || month == 3 || month == 5 || month == 7 || month == 11){ return 1; } return 2; } }
2 Fibonacci Phoenix Tail
Link: Fibonacci Phoenix Tail__ Niuke.com
Source: niuke.com
[programming question] phoenix tail of Fibonacci
- Heat index: 11695 time limit: C/C++ 3 seconds, other languages 6 seconds space limit: C/C++ 32M, other languages 64M
- Video Explanation of algorithm knowledge
NowCoder claims to have memorized all Fibonacci numbers between 1 and 100000.
To test him, we gave him a random number n and asked him to say the nth Fibonacci number. Of course, the Fibonacci number will be very large. Therefore, if the nth Fibonacci number is less than 6, say the number; Otherwise, only the last six digits will be mentioned.
Enter Description:
The input has multiple sets of data. Each group of data has one row, containing an integer n (1 ≤ n ≤ 100000).
Output Description:
Corresponding to each group of inputs, the last 6 bits of the nth Fibonacci number are output.
Example 1
input
1<br/>2<br/>3<br/>4<br/>100000
output
1<br/>2<br/>3<br/>5<br/>537501
- For all codes, note that the output should be printed ("%06d\n", arr[n])
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int[] arr = new int[100001]; arr[0] = 1; arr[1] = 1; for(int i = 2;i < arr.length;i++){ arr[i] = (arr[i-1]+arr[i-2])%1000000; } while (sc.hasNext()) { int n = sc.nextInt(); if (n<26) { System.out.println(arr[n]); }else { System.out.printf("%06d\n",arr[n]); } } } }