題目1
某高校食堂開辦了一個自助餐廳,使用智能餐盤和自動結算,計算學生餐費,
智能餐盤能夠識別所打菜品型別,量,單價(計價單位為:元/100克),
食堂計劃以每道菜、湯獨立定價;主食200克以內免費, 200克以上部分收費( 如果打了多道主食,依據輸入次序累計免費200克以下部分),
為鼓勵學生健康飲食,學校鼓勵學生聯網分享運動資訊,參 照計步數進行階梯折扣, 0-5999步不打折,6000-9999步為9折, 10000步以上均為8折,試根據餐盤提供的資訊和學生的計步數,計算該同學某次用.餐的最終餐費,
輸入說明:
第1行為該生本次用餐所打的所有飯菜種類數量N(0<N≤10) :
第2行起每一行順序為盤中每道飯菜的資訊,包括:型別(M:葷菜/N:素菜/R:主食/S:湯)、重量(克,整數)、
單價(元/100克)
第N+ 2行為該同學的計步數,
輸出說明:最終餐費(保留兩位小數)
輸入樣例:
6
M 50 3.00
V 100 1.50
M 50 5.00
V 150 2.00
R 150 0.10
S 150 0.00
8754
輸出樣例:
7.65
package org.example;/**
* Copyright (C), 2019-2020
* author candy_chen
* date 2020/12/20 13:40
* version 1.0
* Description: 測驗
*/
import java.util.ArrayList;
import java.util.Scanner;
public class Main_01 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
sc.nextLine();
//存盤的資料的
ArrayList<String[]> list = new ArrayList<>();
for (int i = 0; i < N; i++) {
String[] s = sc.nextLine().split(" ");
list.add(s);
}
//存盤步數
int num = sc.nextInt();
//總價格
double sum = 0;
//折扣
double count = 1;
if (num < 5999) {
count = 1;
} else if (num < 9999 && num > 6000) {
count = 0.9;
} else if (num > 10000) {
count = 0.8;
}
for (String[] arr : list) {
if (arr[0].equals("R")) {
if (Integer.valueOf(arr[1]) <= 200) {
continue;
}else {
sum +=( (Integer.valueOf(arr[1]) - 200) * Double.valueOf(arr[2])) / 100;
}
} else {
sum += (Integer.valueOf(arr[1]) * Double.valueOf(arr[2]) / 100);
}
}
double res = sum * count;
System.out.println(String.format("%.2f", res));
}
}
題目2
給定非負整數序列的前兩項a1, a2 ,請按如下規則產生符合要求整數序列:若當前序列的最后2項的乘積為5位數以內的數,則把積作為其后繼項;若當前序列的最后兩項之積為5位數以上的數,則把該數分別對10000求余和求商,把余和商作為其后繼兩項,請輸出所產生的前10項數字,
輸入說明:兩個整數a1, a2.
輸出說明:輸出符合條件的前10項數字,數字之間用空格隔開,所有資料輸出后換行
輸入樣例:
48
輸出樣例:
32 256 8192 7152 209 4768 149 432 71 672
package org.example;/**
* Copyright (C), 2019-2020
* author candy_chen
* date 2020/12/20 13:41
* version 1.0
* Description: 測驗
*/
import java.util.Scanner;
public class Main_02 {
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
int a = cin.nextInt(),b = cin.nextInt();
int ans = 0;
int m = 10;
while (m > 0){
ans = a * b;
if (ans < 10000){
a = b;
b = ans;
System.out.print(b + " ");
m--;
}else if (ans > 10000){
a = ans % 10000;
System.out.print(a + " ");
m--;
if(m > 0){
b = ans / 10000;
System.out.print(b + " ");
m--;
}
}
}
}
}
題目3
給定一個含有N個整數的序列( 2<N<10000 ) ,輸入-一個整數K ( K<N) ,從K的位置把該序列分為2個部分,分別為1到K, K+ 1到N,然后在1到K部分執行從小到大排序;在K+ 1到N部分執行從大到小排序(即前一一部分從小到大,后-部分從大到小) ;然后再從K-2位置把資料分為2個部分,繼續執行上述操作,之后輸出該整數序列,
輸入說明:第一行是正整數N ( 2<N<1000) , 正整數K(2<=K <N),
第二行依次輸入這N個數,
輸出說明:經過操作后的這N個數的序列,數字之間用空格隔開,所有效據輸出后換行
輸入樣例:
10 5
11 2 3 4 5 6 12 8 9 10
輸出樣例:
2 3 4 12 11 10 9 8 6 5
package org.example;/**
* Copyright (C), 2019-2020
* author candy_chen
* date 2020/12/20 13:41
* version 1.0
* Description: 測驗
*/
import java.util.Scanner;
/**
*
*/
public class Main_03 {
public static void swap(int[] a,int i,int j){
int tmp = a[i];
a[i] = a[j];
a[j] = tmp;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int k = sc.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextInt();
}
for (int i = k - 1; i > 0 ; i--) {
for (int j = 0; j < i; j++) {
if (arr[j] > arr[j + 1]){
swap(arr,j,j + 1);
}
}
}
k = k -2;
for(int i = n - 1;i > k;i--){
for (int j = 0;j < i;j++){
if(arr[j] > arr[i]){
swap(arr,j,j+1);
}
}
}
for (int i = n - 1;i > k;i--){
for(int j = k;j < i;j++){
if (arr[j] < arr[j+ 1]){
swap(arr,j,j+ 1);
}
}
}
for (int e : arr) {
System.out.print(e + " ");
}
}
}
題目4
某字串描述了一個單鏈表,但并非嚴格按照節點的順序關系描述,兩個節點的前后關系描述如下:
每個中括號中包含一個節點及 其后繼節點,節點名稱由小寫字母和數字組成,之間由’->’ 連接,表示前驅后繼關系,如[node1-> node2][node3- > node4]node2-> node3]表示鏈表節點的順序為node1-> node2-> node3-> node4 ;
輸入一個字串,給定一個節點名稱,求該節點到鏈表頭尾的距離長度,
輸入說明:
第一行為單鏈表的描述字串(長度s200) ,第二行為給定節點的名稱; .
輸出說明:
該節點到鏈表頭、尾的距離長度,空格隔開;
輸入樣例:
[node1-> node2] [node3-> node4] [node2->node3]
node2
輸出樣例:
12
第四題投機取巧了一下,,,不知道結果咋樣
package org.example;/**
* Copyright (C), 2019-2020
* author candy_chen
* date 2020/12/20 13:41
* version 1.0
* Description: 測驗
*/
import java.util.Scanner;
public class Main_04 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String s1 = sc.nextLine();
String s2 = sc.nextLine();
int des = (int)s2.charAt(4);
int max = Integer.MIN_VALUE;
int min = Integer.MAX_VALUE;
for (int i = 0; i < s1.length(); i++) {
if (s1.charAt(i) >= '0' && s1.charAt(i) <= '9'){
int tmp = (int) s1.charAt(i);
if (tmp > max){
max = tmp;
}
if (tmp < min){
min = tmp;
}
}
}
System.out.println((des - min) + " " + (max -des));
}
}
題目5
公交車換乘城市推出了優惠換乘活動,乘客第一-次在公交車 上打卡后,可以免費同站臺換乘2次,現給出城市中多條公交路線,每個公交站有一一個編號,編號由一個字母和- -位或兩位數字組成,給定某乘客的出發站.問2次換乘,最多可以經過多少個不同的公交站,
輸入說明:第一行是一個整數N ( 1<N<=20 )和出發站編號,其中N表示公交路線數量,接下來N行,每行表示一條公交路線的所有停靠站編號(單條線路的停靠站數量少于20) , 中間用空格隔開,已知公交線路不會形成環線,
輸出說明: 一個整數,表示不超過2次換乘,最多可以經過多少個不同的公交站,
輸入樣例:
3 C3
A1 A2 A3
C1 C2 C3 C4
A2 B1 C2 D1
輸出樣例;
5
不會、、、、、
題目6
倉庫中有m袋大米,它們的重是互不相同,分別N1. N2、… Nm千克,東方學校食堂需要大米N干克,需要從倉庫中挑選若干袋大米,重最之和恰好N千克,請統計一共有多少種組合方法,使得重量符合要求,
輸入說明:第一行輸入兩個正整數,分別為m ( m<=60,為大米袋數)和N ( N<= 1000 ,為需要大米重量) ,第二行輸入m個正整數,表示m袋大米重量(已知每袋大米重量不超過200千克)
輸出說明:選擇若干袋大米,重量恰好為N的不同組合方法總數
輸入樣例:
5 20
3 4 11 2 9
輸出樣例:
2
(第六題參賽的時候沒寫出來,后來莊小炎給的代碼)
package org.example;/**
* Copyright (C), 2019-2020
* author candy_chen
* date 2020/12/20 13:41
* version 1.0
* Description: 測驗
*/
import java.util.*;
public class Main_06 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int target = sc.nextInt();
int[] num = new int[m];
for (int i = 0; i < m; i++) {
num[i] = sc.nextInt();
}
Arrays.sort(num);
ArrayList<ArrayList<Integer>> arrayLists = combinationSum2(num, target);
System.out.println(arrayLists.size());
}
static ArrayList<ArrayList<Integer>> list = new ArrayList<>();
public static ArrayList<ArrayList<Integer>> combinationSum2(int[] num, int target) {
ArrayList<Integer> ls = new ArrayList<>();
if (num == null || num.length == 0) {
return list;
}
Arrays.sort(num);
dfs(num, 0, target, ls);
return list;
}
private static void dfs(int[] arr, int index, int sum, ArrayList<Integer> ls) {
if (sum < 0) {
return;
}
if (sum == 0) {
if (!list.contains(ls)) {
list.add(new ArrayList<>(ls));
}
return;
}
for (int i = index; i < arr.length; i++) {
ls.add(arr[i]);
//此處從i+1開始
dfs(arr, i + 1, sum - arr[i], ls);
ls.remove(ls.size() - 1);
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/238059.html
標籤:其他
上一篇:第 45 屆國際大學生程式設計競賽(ICPC)亞洲區域賽(南京)(熱身賽)
下一篇:當代大學生結課后的一周
