20231122

本文展示了如何使用C++编写一个简单的程序,通过判断数字是否包含特定字符1122来计算2023年11月22日期间的计数,这是集美大学第15届蓝桥杯大赛软件类校内选拔赛的一个示例。
摘要由CSDN通过智能技术生成
  • 9
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
好的,可以使用Java的File类来实现这个操作。以下是一个可能的实现: ```java import java.io.File; import java.util.HashMap; import java.util.Map; public class FileGroup { private Map<String, FileGroupItem> items = new HashMap<>(); public void groupFiles(String basePath) { File root = new File(basePath); File dateDir = new File(root, "20231122"); File[] subDirs = dateDir.listFiles(File::isDirectory); if (subDirs != null) { for (File subDir : subDirs) { String dirName = subDir.getName(); FileGroupItem item = new FileGroupItem(dirName); items.put(dirName, item); File[] files = subDir.listFiles(); if (files != null) { for (File file : files) { String fileName = file.getName(); if (fileName.endsWith(".pdf")) { item.addPdfPath(file.getAbsolutePath()); } else if (fileName.endsWith(".jpg") || fileName.endsWith(".png")) { item.addPhotoPath(file.getAbsolutePath()); } else if (fileName.endsWith(".mp4") || fileName.endsWith(".avi")) { item.addVideoPath(file.getAbsolutePath()); } } } } } } public static void main(String[] args) { FileGroup group = new FileGroup(); group.groupFiles("hdgk"); System.out.println(group); } @Override public String toString() { return "FileGroup{" + "items=" + items + '}'; } } class FileGroupItem { private String name; private String[] photoPaths = new String[0]; private String[] videoPaths = new String[0]; private String[] pdfPaths = new String[0]; public FileGroupItem(String name) { this.name = name; } public void addPhotoPath(String path) { photoPaths = addToArray(photoPaths, path); } public void addVideoPath(String path) { videoPaths = addToArray(videoPaths, path); } public void addPdfPath(String path) { pdfPaths = addToArray(pdfPaths, path); } private String[] addToArray(String[] array, String item) { String[] newArray = new String[array.length + 1]; System.arraycopy(array, 0, newArray, 0, array.length); newArray[array.length] = item; return newArray; } @Override public String toString() { return "FileGroupItem{" + "name='" + name + '\'' + ", photoPaths=" + Arrays.toString(photoPaths) + ", videoPaths=" + Arrays.toString(videoPaths) + ", pdfPaths=" + Arrays.toString(pdfPaths) + '}'; } } ``` 这个程序会读取名为 `hdgk` 的文件夹下的 `20231122` 子文件夹,并在其中查找名为 `photo`、`video` 和 `pdf` 的子文件夹。然后,它将这些文件夹中的所有文件路径分别存储到一个 `FileGroupItem` 对象中,并将这些对象存储到一个 `FileGroup` 对象中,以便按照日期分组。可以在 `main` 方法中调用 `groupFiles` 方法,并查看 `FileGroup` 对象的输出来查看结果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值