/*
ID: fykalv3
LANG: C
TASK: namenum
*/
#include <stdio.h>
#include <string.h>
/*
我觉得这道题是我学到思想比较多的,题目上来很繁琐,一开始想的是把输入的数字下的所有的名字都列举了然后再去字典里面搜索,工作量太大了,后来觉得可以遍历字典中的每个字符串转换成数字和输入的数字匹配,写程序时间不长,我觉得这个算法有很大的优化空间,以后再写写慢慢回来优化
*/
int main()
{
FILE *fin = fopen("namenum.in", "r");
FILE *fout = fopen("namenum.out", "w");
int num[26] = {2, 2, 2, 3, 3, 3, 4, 4, 4, 5, 5, 5, 6, 6, 6, 7, 0, 7, 7, 8, 8, 8, 9, 9, 9, 0};
int name[13];
char temp[13], les[13];
int i, j, k;
fscanf(fin, "%s", temp);
k = strlen(temp);
for (i = 0; i < k; i++)
name[i] = temp[i] - '0';
name[i] = 0;
freopen("dict.txt", "r", stdin); // 文件的操作,第一次用
j = 0;
while (scanf("%s", les) != EOF) { //和上面的文件操作配合来
i = 0;
while (les[i++] != '\0') {
if (num[les[i] - 'A'] != name[i]) // les是dict中读入的字符串,转换ASCII码,在num中找到字母对应的数字然后比较
break;
}
if (les[i] == '\0' && name[i] == 0) { // 注意这里要同时达到les和name的末尾,多一个mark的地方
fprintf(fout, "%s\n", les);
j = 1; //这里是mark找没找到合适的匹配
}
}
if (j == 0)
fprintf(fout, "NONE\n");
fclose(fin);
fclose(fout);
return 0;
}
分享到:
相关推荐
USACO答案,采用C++写的,题目是:name that number.
【Title】: USACO题目"Name That Number (namenum)"及代码解析 【Description】: 本题属于USACO竞赛中的一道题目,要求编写一个程序,将母牛的烙印编号转换为可能的牛名。这些名字是根据特定的数字到字母的映射规则...
5 [1.2] 命名那个数字 Name That Number 6 [1.2] 挤牛奶Milking Cows 7 [1.2] 方块转换 Transformations 8 [1.2] 回文平方数 Palindromic Squares 9 [1.2] 双重回文数 Dual Palindromes 10 [1.3] 混合牛奶 Mixing ...
1.2.3 "Name That Number" 可能是关于数字表示和逻辑推理的问题。 1.2.4 "Palindromic Squares" 和 "Dual Palindromes" 强调了对回文数的理解和生成算法。 1.3.1 "Mixing Milk" 和 "Barn Repair" 可能涉及到更复杂的...
接着,1.2节重点是完整搜索,如"Milking Cows"中运用离散化技术,"Transformations"和"Name That Number"通过枚举解决,而"Palindromic Squares"和"Dual Palindromes"进一步强化了枚举法的应用。 1.3节围绕贪心算法...
6. **动态规划和组合**:"Name That Number"中,可能需要使用动态规划或回溯法来生成所有可能的数字组合,然后与输入的数字进行比较。这将降低算法复杂度,提高解决问题的效率。 7. **回文数检查**:"Palindromic ...
此外,“Transformations”、“Name That Number”等题目进一步加深了对模拟算法的理解。 ### 四、Chapter3:Techniques more subtle 第三章深入探讨了更精细的技术,如“Mixing Milk”题目虽然可能通过模拟解决,...
- “NameThatNumber”和“CheckerChallenge”等题目可能与字符串处理有关。字符串处理是编程中常见的问题,需要参赛者对字符串的各种操作有较深的了解。 6. 数学计算(Math Computation): - “PrimeCryptarithm”...
#### Name That Number 此题要求根据给定的条件猜出一个数字。这类问题常常涉及数学推理和逻辑分析,可以通过枚举法、二分查找等算法来逐步缩小可能的数字范围,直至找到正确的答案。 #### Palindromic Squares ...
p04 apple 10 banana 25 carrot 100Echo your data.Your program should read the parameters create threads for the words and have that thread count 1 to N (the number following).You should use the ...
For this assignment, we will read ... Each non-blank line will contain an integer score followed by one or more blanks, followed by a department name that may contain embedded blanks (Computer Science).
withdrawal function that returns a bool value deposit function that returns a bool value a way to get available funds should return a double a way to create an account that returns bool value ...
borrower (customer name, loan number) account (account number, branch_name, balance ) depositor (customer name, account_number) a. Find all customers who have an account at all the branches located ...
You may assume that the number of data entry will never exceed 100. 2) List the students’ data (name and score pairs) arranged according to the score in a descending order. At the bottom of the list...
“H123456789”), owner’s name (e.g. “David Fox”), due date (e.g. 01/01/2011), length (e.g. 5.4 meters), gross mass (e.g. 2500 kg). You may add necessary methods in the class defined above. Define ...
4. 记忆单词技巧:记忆单词时可以关联生活场景,比如打电话要拨打 "telephone number",乘坐飞机需要 "ID card",表明自己用 "I am…",打招呼可以用 "Hi/Hello",介绍名字用 "My name is…",他/她的名字则用 "his/...
For each USB device, exteneded information is displayed: Device name/description, device type, serial number (for mass storage devices), the date/time that device was added, VendorID, ProductID, and ...
name/description, device type, serial number (for mass storage devices), the date/time that device was added, VendorID, ProductID, and more... USBDeview also allows you to uninstall USB devices that ...
Write a program that prompts the user to enter the name of an ASCII text file and display the frequency of the letters in the file using following design: public class ShowFrequency { public ...