#1-【gdgzoi.com解题】虫子的学号

Description

lc是一名虫子老师,刚刚教完一届,准备带新的一年级小虫子。你手上有一份他们自己登记的学号名单,学号的标准格式为:xxx-xxxx(x为数字),例如000-0000。但是小虫子们很健忘,老是不记得自己登记学号了没有,所以他们经常重复登记自己的学号,而且每次登记的学号格式都有可能不一样。虫子校长为了刁难老师,允许他们在数字之间的任意位置添加“-”,例如,3-10-10-10的标准格式是310-1010。校长还有一个更恶毒的手段:他给每只小虫子发一个密码本,小虫子们可以按密码本改自己的学号,密码本如下:

A, B, 和C 表示 2 
D, E, 和F 表示 3 
G, H, 和I表示4 
J, K, 和L表示5 
M, N, 和O表示6 
P, R, 和S表示7 
T, U, 和V表示8 
W, X, 和Y表示9 

Q和Z不表示任何数字。

例如:TUT-GLOP的标准格式是888-4567,310-GINO的标准格式是310-4466。如果两个学号的标准格式是相同的,那么他们是同一只小虫子登记的。由于lc太愚蠢了,他想找你帮他找出重复的学号和重复的次数。

Input

第一行一个整数n(0≤n≤100000)表示名单上学号的总个数,接下来你行每行一个学号(不包含Q和Z),每个学号中刚好有7个数字或字母。

Output

对于每个出现重复的学号产生一行输出,输出是学号的标准格式紧跟一个空格然后是它的重复次数。如果存在多个重复的学号,则按照学号的字典序升序输出。

Sample Input

12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279

 

Sample Output

310-1010 2

487-3279 4

888-4567 3

 

典型的桶排序。

AC Code:

#include <iostream>
#include <string>
 
#define SIZE 10000000
 
using namespace std;
 
int a[SIZE];
int c[127];
string s;
 
void start(void)
{
    #if 0
    A, B, ?C ?? 2 
    D, E, ?F ?? 3 
    G, H, ?I??4 
    J, K, ?L??5 
    M, N, ?O??6 
    P, R, ?S??7 
    T, U, ?V??8 
    W, X, ?Y??9 
    #endif
    int i;
     
    c['Q'] = c['Z'] = c['-'] = -1;
    c['0'] = 0;
    c['1'] = 1;
    c['A'] = c['B'] = c['C'] = c['2'] = 2;
    c['D'] = c['E'] = c['F'] = c['3'] = 3;
    c['G'] = c['H'] = c['I'] = c['4'] = 4;
    c['J'] = c['K'] = c['L'] = c['5'] = 5;
    c['M'] = c['N'] = c['O'] = c['6'] = 6;
    c['P'] = c['R'] = c['S'] = c['7'] = 7;
    c['T'] = c['U'] = c['V'] = c['8'] = 8;
    c['W'] = c['X'] = c['Y'] = c['9'] = 9;
     
    return;
}
 
int main(int argc, char** argv)
{
    int n, i, temp;
     
    cin >> n;
    start();
    while (n--)
    {
        temp = 0;
        cin >> s;
        for (i = 0; i < s.size(); i++)
        {
            if (c[s[i]] == -1)
            {
                continue;
            }
            temp *= 10;
            temp += c[s[i]];
        }
        a[temp]++;
    }
     
    for (i = 0; i < SIZE; i++)
    {
        if (a[i] > 1)
        {
            printf("%d-%d %d\n", i / 10000, i % 10000, a[i]);
        }
    }
     
    return 0;
}

附加:这是原题(gdgzoi改了一下)

487-3279
Time Limit: 2000MS	
Memory Limit: 30000K
Total Submissions: 59071	
Accepted: 9916
Description
Businesses like to have memorable telephone numbers. One way to make a telephone number memorable is to have it spell a memorable word or phrase. For example, you can call the University of Waterloo by dialing the memorable TUT-GLOP. Sometimes only part of the number is used to spell a word. When you get back to your hotel tonight you can order a pizza from Gino's by dialing 310-GINO. Another way to make a telephone number memorable is to group the digits in a memorable way. You could order your pizza from Pizza Hut by calling their ``three tens'' number 3-10-10-10. 

The standard form of a telephone number is seven decimal digits with a hyphen between the third and fourth digits (e.g. 888-1200). The keypad of a phone supplies the mapping of letters to numbers, as follows: 

A, B, and C map to 2 
D, E, and F map to 3 
G, H, and I map to 4 
J, K, and L map to 5 
M, N, and O map to 6 
P, R, and S map to 7 
T, U, and V map to 8 
W, X, and Y map to 9 

There is no mapping for Q or Z. Hyphens are not dialed, and can be added and removed as necessary. The standard form of TUT-GLOP is 888-4567, the standard form of 310-GINO is 310-4466, and the standard form of 3-10-10-10 is 310-1010. 

Two telephone numbers are equivalent if they have the same standard form. (They dial the same number.) 

Your company is compiling a directory of telephone numbers from local businesses. As part of the quality control process you want to check that no two (or more) businesses in the directory have the same telephone number. 


Input
The input will consist of one case. The first line of the input specifies the number of telephone numbers in the directory (up to 100,000) as a positive integer alone on the line. The remaining lines list the telephone numbers in the directory, with each number alone on a line. Each telephone number consists of a string composed of decimal digits, uppercase letters (excluding Q and Z) and hyphens. Exactly seven of the characters in the string will be digits or letters. 

Output
Generate a line of output for each telephone number that appears more than once in any form. The line should give the telephone number in standard form, followed by a space, followed by the number of times the telephone number appears in the directory. Arrange the output lines by telephone number in ascending lexicographical order. If there are no duplicates in the input print the line: 

No duplicates. 

Sample Input

12
4873279
ITS-EASY
888-4567
3-10-10-10
888-GLOP
TUT-GLOP
967-11-11
310-GINO
F101010
888-1200
-4-8-7-3-2-7-9-
487-3279
Sample Output

310-1010 2
487-3279 4
888-4567 3
Source
East Central North America 1999

 

ren"蔡诗琦-答题截图.jpg" 25计算机4班蔡诗琦.jpg ren"蔡顺鑫-答题截图.jpg" 25计算机4班蔡顺鑫.jpg ren"蔡宇浩-答题截图.jpg" 25计算机4班蔡宇浩.jpg ren"曾继铉-答题截图.jpg" 25计算机4班曾继铉.jpg ren"陈嘉莹-答题截图.jpg" 25计算机4班陈嘉莹.jpg ren"陈俊楷-答题截图.jpg" 25计算机4班陈俊楷.jpg ren"陈俊良-答题截图.jpg" 25计算机4班陈俊良.jpg ren"陈悦心-答题截图.jpg" 25计算机4班陈悦心.jpg ren"陈政宇-答题截图.jpg" 25计算机4班陈政宇.jpg ren"范柯炜-答题截图.jpg" 25计算机4班范柯炜.jpg ren"范伟慧-答题截图.jpg" 25计算机4班范伟慧.jpg ren"韩铖轩-答题截图.jpg" 25计算机4班韩铖轩.jpg ren"黄志锋-答题截图.jpg" 25计算机4班黄志锋.jpg ren"霍东升-答题截图.jpg" 25计算机4班霍东升.jpg ren"江嘉怡-答题截图.jpg" 25计算机4班江嘉怡.jpg ren"黎逸希-答题截图.jpg" 25计算机4班黎逸希.jpg ren"李泓大-答题截图.jpg" 25计算机4班李泓大.jpg ren"林庆鸿-答题截图.jpg" 25计算机4班林庆鸿.jpg ren"林伊洵-答题截图.jpg" 25计算机4班林伊洵.jpg ren"林仲优-答题截图.jpg" 25计算机4班林仲优.jpg ren"刘宇航-答题截图.jpg" 25计算机4班刘宇航.jpg ren"龙子琦-答题截图.jpg" 25计算机4班龙子琦.jpg ren"罗檫枢-答题截图.jpg" 25计算机4班罗檫枢.jpg ren"马展宏-答题截图.jpg" 25计算机4班马展宏.jpg ren"莫文轩-答题截图.jpg" 25计算机4班莫文轩.jpg ren"潘芊睿-答题截图.jpg" 25计算机4班潘芊睿.jpg ren"彭飞哲-答题截图.png" 25计算机4班彭飞哲.png ren"彭新磊-答题截图.jpg" 25计算机4班彭新磊.jpg ren"丘文浩-答题截图.jpg" 25计算机4班丘文浩.jpg ren"谭小峰-答题截图.jpg" 25计算机4班谭小峰.jpg ren"谭奕锋-答题截图.jpg" 25计算机4班谭奕锋.jpg ren"王钦樁-答题截图.jpg" 25计算机4班王钦樁.jpg ren"王瑜彦-答题截图.jpg" 25计算机4班王瑜彦.jpg ren"吴锦丽-答题截图.jpg" 25计算机4班吴锦丽.jpg ren"吴俊杰-答题截图.jpg" 25计算机4班吴俊杰.jpg ren"吴旋齐-答题截图.jpg" 25计算机4班吴旋齐.jpg ren"肖明进-答题截图.jpg" 25计算机4班肖明进.jpg ren"姚力扬-答题截图.jpg" 25计算机4班姚力扬.jpg ren"张芷瑜-答题截图.jpg" 25计算机4班张芷瑜.jpg ren"赵润棋-答题截图.jpg" 25计算机4班赵润棋.jpg ren"郑泓锐-答题截图.jpg" 25计算机4班郑泓锐.jpg ren"郑嘉珍-答题截图.jpg" 25计算机4班郑嘉珍.jpg ren"周锦晨-答题截图.jpg" 25计算机4班周锦晨.jpg ren"周子豪-答题截图.jpg" 25计算机4班周子豪.jpg ren"庄灿佳-答题截图.jpg" 25计算机4班庄灿佳.jpg
最新发布
11-26
<think> 根据用户需求,需要将文件名从&#39;姓名-答题截图.jpg/png&#39;重命名为&#39;25计算机4班姓名.jpg/png&#39; 关键点: 1. 原文件名格式:姓名-答题截图.扩展名(如:张三-答题截图.jpg) 2. 目标文件名格式:25计算机4班姓名.扩展名(如:25计算机4班张三.jpg) 3. 需要批量处理 步骤: 1. 获取当前目录下所有符合原文件名格式的文件(即包含“-答题截图”的jpg或png文件) 2. 提取原文件名中的“姓名”部分(即“-答题截图”前面的部分) 3. 构建新文件名:固定前缀“25计算机4班”+姓名+原扩展名 4. 重命名文件 注意:原文件名中可能包含多个“-”,但我们要的是第一个“-”之前的部分作为姓名?还是按照固定分隔符“-答题截图”来分割? 用户给出的原文件名格式是“姓名-答题截图”,所以我们可以用“-答题截图”作为分隔符来提取姓名。 例如: 原文件名:张三-答题截图.jpg -> 提取姓名“张三”,新文件名为:25计算机4班张三.jpg 实现方式(以Python脚本为例): </think> # 批量重命名文件:从&#39;姓名-答题截图&#39;到&#39;25计算机4班姓名&#39; 以下是使用Python脚本实现批量重命名文件的解决方案: ```python import os import re # 设置工作目录(包含待重命名的文件) directory = &#39;./&#39; # 更改为实际目录路径 # 遍历目录中的所有文件 for filename in os.listdir(directory): # 只处理符合条件的图片文件(jpg或png) if filename.endswith((&#39;.jpg&#39;, &#39;.png&#39;)) and &#39;-答题截图&#39; in filename: # 提取姓名部分(去除"-答题截图") name_part = re.split(r&#39;-答题截图&#39;, filename)[0] # 提取文件扩展名 file_ext = os.path.splitext(filename)[1] # 构建新文件名:25计算机4班 + 姓名 + 扩展名 new_filename = f"25计算机4班{name_part}{file_ext}" # 构建完整文件路径 old_path = os.path.join(directory, filename) new_path = os.path.join(directory, new_filename) # 执行重命名操作 os.rename(old_path, new_path) print(f"重命名: {filename} -> {new_filename}") print("批量重命名完成!") ``` ## 使用说明 1. **准备工作**: - 确保Python已安装(推荐Python 3.6+) - 将所有需要重命名的文件放在同一文件夹中 2. **修改脚本参数**: - 将 `directory = &#39;./&#39;` 中的路径改为包含文件的目录路径 - 例如:`directory = &#39;C:/Users/YourName/Documents/答题图片&#39;` 3. **运行脚本**: - 将脚本保存为 `rename_files.py` - 在命令行中运行:`python rename_files.py` ## 脚本功能说明 1. **文件筛选**: - 仅处理jpg和png格式的文件 - 只处理包含"-答题截图"的文件名 2. **姓名提取**: - 使用正则表达式分割文件名,提取姓名部分 - 例如:"张三-答题截图.jpg" → "张三" 3. **新文件名构建**: - 格式:`25计算机4班姓名.扩展名` - 例如:"25计算机4班张三.jpg" ## 执行前注意事项 1. **备份文件**: - 建议先复制一份原始文件作为备份 2. **文件名一致性**: - 确保所有文件名都符合"姓名-答题截图.扩展名"格式 - 如果姓名中包含"-",可能导致提取错误 3. **权限检查**: - 确保脚本有权限修改目标目录中的文件 ## 示例效果 | 原文件名 | 新文件名 | |-------------------|-----------------------| | 张三-答题截图.jpg | 25计算机4班张三.jpg | | 李四-答题截图.png | 25计算机4班李四.png | | 王五-答题截图.jpg | 25计算机4班王五.jpg | ## 相关问题 1. 如果文件名中包含多个"-",如何准确提取姓名部分? 2. 如何同时处理不同格式的图片文件(如JPG、JPEG、PNG等)? 3. 如何在重命名后保留原始文件的时间戳信息? 4. 如何批量处理子目录中的文件而不仅仅是当前目录? 5. 如果某些文件已经存在目标文件名,如何避免覆盖冲突? > **提示**:对于更复杂的重命名需求,可以考虑使用Python的`pathlib`库或专业文件重命名工具如Bulk Rename Utility[^1]。 [^1]: 关于文件批量处理的更多方法,参考Python官方文档[os模块](https://docs.python.org/3/library/os.html
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值