当前位置: 首页 > news >正文

面试实例题

 题目

 Java

package day4;import java.time.LocalDateTime;
import java.time.Duration;public class demo2 {public static void main(String[] args) {LocalDateTime freezeStart = LocalDateTime.of(2025, 6, 5, 14, 24, 50);LocalDateTime freezeEnd = freezeStart.plusDays(7);while (LocalDateTime.now().isBefore(freezeEnd)) {Duration duration = Duration.between(LocalDateTime.now(), freezeEnd);long days = duration.toDays();long hours = duration.minusDays(days).toHours();long minutes = duration.minusDays(days).minusHours(hours).toMinutes();long seconds = duration.minusDays(days).minusHours(hours).minusMinutes(minutes).getSeconds();System.out.printf("您的卡已被冻结,解冻时间是 %d 天 %d 小时 %d 分 %d 秒%n", days, hours, minutes, seconds);try {Thread.sleep(1000);} catch (InterruptedException e) {e.printStackTrace();}}}
}
import java.util.LinkedList;class Stock {String name;String code;String increaseRate;String riseFall;public Stock(String name, String code, String increaseRate, String riseFall) {this.name = name;this.code = code;this.increaseRate = increaseRate;this.riseFall = riseFall;}
}public class StockDisplay {public static void main(String[] args) {LinkedList<Stock> stockList = new LinkedList<>();stockList.add(new Stock("三祥新材", "603663", "-1.12%", "-0.26"));stockList.add(new Stock("合众思壮", "002383", "-0.21%", "-0.02"));stockList.add(new Stock("东望时代", "600052", "-0.24%", "-0.01"));stockList.add(new Stock("成飞集成", "002190", "4.78%", "1.72"));stockList.add(new Stock("易德龙", "603380", "0.45%", "0.11"));for (Stock stock : stockList) {System.out.println("股票名称:" + stock.name);System.out.println("股票代码:" + stock.code);System.out.println("涨幅:" + stock.increaseRate);System.out.println("涨跌:" + stock.riseFall);System.out.println("------------------");}}
}

C语言

#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <string.h>
typedef struct {char a[5];char b[3];char c[3];char d[3];char e[3];char f[3];
} DateTime;
typedef struct {DateTime g;int h;int i;int j;
} CardStatus;
void initCardStatus(CardStatus* k) {strcpy(k->g.a, "2025");strcpy(k->g.b, "06");strcpy(k->g.c, "05");strcpy(k->g.d, "14");strcpy(k->g.e, "24");strcpy(k->g.f, "50");k->h = 6 * 24 * 3600 + 23 * 3600 + 59 * 60 + 30;k->i = k->h;k->j = 1;
}
time_t dateTimeToTimeT(DateTime* l) {struct tm m = { 0 };m.tm_year = atoi(l->a) - 1900;m.tm_mon = atoi(l->b) - 1;m.tm_mday = atoi(l->c);m.tm_hour = atoi(l->d);m.tm_min = atoi(l->e);m.tm_sec = atoi(l->f);return mktime(&m);
}
void secondsToDHMS(int n, int* o, int* p, int* q, int* r) {*o = n / (24 * 3600);*p = (n % (24 * 3600)) / 3600;*q = (n % 3600) / 60;*r = n % 60;
}
void updateFreezeStatus(CardStatus* s) {if (s->i > 0) {s->i--;}else {s->j = 0;}
}
void displayRemainingTime(CardStatus* t) {int o, p, q, r;secondsToDHMS(t->i, &o, &p, &q, &r);system("cls");printf("您的卡已被冻结,剩余时间为 %d 天 %d 小时 %d 分 %d 秒\n",o, p, q, r);
}
int main() {CardStatus u;initCardStatus(&u);while (u.j) {displayRemainingTime(&u);sleep(1);updateFreezeStatus(&u);}printf("您的卡已解冻,可以正常使用。\n");return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct Stock {char code[10];char name[20];float change_rate;float change_price;struct Stock* next; 
} Stock;
Stock* create_node(char* code, char* name, float rate, float price) {Stock* node = (Stock*)malloc(sizeof(Stock));strcpy(node->code, code);strcpy(node->name, name);node->change_rate = rate;node->change_price = price;node->next = NULL;return node;
}
void append_node(Stock** head, char* code, char* name, float rate, float price) {Stock* new_node = create_node(code, name, rate, price);if (*head == NULL) {*head = new_node;return;}Stock* current = *head;while (current->next != NULL) current = current->next;current->next = new_node;
}
void display_stocks(Stock* head, int page_size) {Stock* current = head;int count = 0;printf("%-10s %-15s %-10s %-10s\n", "代码", "名称", "涨幅", "涨跌");printf("----------------------------------------\n");while (current != NULL && count < page_size) {printf("%-10s %-15s %-10.2f%% %-10.2f\n",current->code, current->name,current->change_rate, current->change_price);current = current->next;count++;}
}
int main() {Stock* head = NULL;append_node(&head, "603663", "三祥新材", -1.12, -0.26);append_node(&head, "002383", "合众思壮", -0.21, -0.02);append_node(&head, "600052", "东望时代", -0.24, -0.01);append_node(&head, "002190", "成飞集成", 4.78, 1.72);append_node(&head, "603380", "易德龙", 0.45, 0.11);display_stocks(head, 5);Stock* temp;while (head != NULL) {temp = head;head = head->next;free(temp);return 0; 
}
}

相关文章:

  • 【P2P】低延迟直播(尤其是 P2P 实时分发)常用的 x264 编码参数示例
  • 小游戏不能玩了?最好用flash扩展程序
  • 计算机网络笔记(三十)——5.2用户数据报协议UDP
  • 什么是贫血模式
  • FastAPI实战起步:从Python环境到你的第一个“Hello World”API接口
  • 哈希map中不能将数组作为键的原因 leetcode49
  • JavaScript 内置对象全解析
  • TM中,return new TransactionManagerImpl(raf, fc);为什么返回是new了一个新的实例
  • 《从函数模板到类模板:OP泛型编程进化论》
  • Python项目的构建和部署方案推荐
  • QTreeWidget 应用场景与用法详解
  • Docker部署SpringBoot项目
  • 6月8日python-AI代码
  • 面向对象之 继承中的成员访问特点
  • TCP相关问题 第一篇
  • 鸿蒙的一些布局
  • 深入剖析JVM垃圾回收,高并发场景JVM性能调优,内存泄露分析,以及如何避免OOM
  • 8个AI软件介绍及其工作原理讲解
  • Day 21
  • Hilt在android项目中使用的注解说明
  • 怎么做网站的需求/成功营销案例分享
  • ie兼容性 网站/江苏网站seo设计
  • 政府网站域名要求/上海seo优化
  • 河北集团网站建设/seo和sem的区别与联系
  • notepad做网站技巧/主流搜索引擎有哪些
  • 做网站优化的好处/淘宝关键词指数