/*
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.
USACO题目Name That Number (namenum)及代码解析
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 ...
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 ...
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 ...
That is, the user will give it a few searches (some on first name, some on last name, some on telephone number, some on city). The Main Point The time to search in an unsorted list is O(n). The time ...
Even more true to its name, the game chooses to communicate so that the base of the number system is minus two, not plus two, so we’ll call this representation “Weird Binary”. Thus the bit ...
will be a single line containing an integer ne that specifies the number of sequential events in the computation followed by ne event IDs. Following the specification of the events in the last ...
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 ...
This book is divided into three major sections.... We hope that students will appreciate that the study of simulation ties together, or unifies, material from a number of separate areas of study.
There are any number of "resheader" rows that contain simple name/value pairs. Each data row contains a name, and value. The row also contains a type or mimetype. Type corresponds to a .NET ...
For all students, the common information about a student includes the student’s name (first name and last name), the student’s ID, and a category that indicates which category the student belongs ...