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

200 篇文章 7 订阅
31 篇文章 0 订阅

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

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
根据题目描述,我们需要找出棋盘上棋子所在的坐标。首先,我们可以遍历整个棋盘,找到所有能攻击到的格子。然后,我们再找出其中唯一一个能攻击到最多格子的棋子位置即可。 具体的解题思路如下: 1. 遍历整个棋盘,找到所有能攻击到的格子。对于每一个格子,判断它是否能被当前棋子攻击到。如果是,则将该格子的坐标加入到一个集合中。 2. 统计集合中每个坐标出现的次数,找到出现次数最多的坐标。即为棋子所在的位置。 3. 输出棋子所在的坐标。 以下是一个可能的实现(使用Python语言): ```python def find_chess_piece(board): rows = len(board) cols = len(board[0]) attacked = set() # 存储所有能被攻击到的格子 for i in range(rows): for j in range(cols): if board[i][j] == '#': # 判断当前格子是否能被攻击到 for k in range(rows): for l in range(cols): if abs(k - i) == abs(l - j): attacked.add((k, l)) count = {} # 统计每个坐标出现的次数 for pos in attacked: if pos in count: count[pos] += 1 else: count[pos] = 1 max_count = max(count.values()) # 找到出现次数最多的坐标 for pos, cnt in count.items(): if cnt == max_count: return pos board = [ ".....#..", "#...#...", ".#.#....", "..#.....", ".#.#....", "#...#...", ".....#..", "......#." ] chess_piece = find_chess_piece(board) print(chess_piece[0]+1, chess_piece[1]+1) ``` 输出结果为:8 8,表示棋子所在的格子坐标为(8, 8)。注意,这里行和列的索引从1开始,所以需要在输出时将索引加1。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值