`
kalviny
  • 浏览: 5543 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
最近访客 更多访客>>
社区版块
存档分类
最新评论

Name That Number

阅读更多
/*
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答案name that number

    USACO答案,采用C++写的,题目是:name that number.

    USACO题目Name That Number (namenum)及代码解析

    【Title】: USACO题目"Name That Number (namenum)"及代码解析 【Description】: 本题属于USACO竞赛中的一道题目,要求编写一个程序,将母牛的烙印编号转换为可能的牛名。这些名字是根据特定的数字到字母的映射规则...

    USACO官网93题fps格式 OJ题库

    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 ...

    USACO英汉对照题目

    1.2.3 "Name That Number" 可能是关于数字表示和逻辑推理的问题。 1.2.4 "Palindromic Squares" 和 "Dual Palindromes" 强调了对回文数的理解和生成算法。 1.3.1 "Mixing Milk" 和 "Barn Repair" 可能涉及到更复杂的...

    第1章总结1

    接着,1.2节重点是完整搜索,如"Milking Cows"中运用离散化技术,"Transformations"和"Name That Number"通过枚举解决,而"Palindromic Squares"和"Dual Palindromes"进一步强化了枚举法的应用。 1.3节围绕贪心算法...

    usaco题目的副本1

    6. **动态规划和组合**:"Name That Number"中,可能需要使用动态规划或回溯法来生成所有可能的数字组合,然后与输入的数字进行比较。这将降低算法复杂度,提高解决问题的效率。 7. **回文数检查**:"Palindromic ...

    USACO总结

    此外,“Transformations”、“Name That Number”等题目进一步加深了对模拟算法的理解。 ### 四、Chapter3:Techniques more subtle 第三章深入探讨了更精细的技术,如“Mixing Milk”题目虽然可能通过模拟解决,...

    USACO全部译题

    - “NameThatNumber”和“CheckerChallenge”等题目可能与字符串处理有关。字符串处理是编程中常见的问题,需要参赛者对字符串的各种操作有较深的了解。 6. 数学计算(Math Computation): - “PrimeCryptarithm”...

    USACO全部题目

    #### Name That Number 此题要求根据给定的条件猜出一个数字。这类问题常常涉及数学推理和逻辑分析,可以通过枚举法、二分查找等算法来逐步缩小可能的数字范围,直至找到正确的答案。 #### Palindromic Squares ...

    OS1.docx_readparameters_cubbyhole_CodeName_os_commandline_

    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 ...

    Score Analysis程序代码

    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).

    Bank buser account的小型c++模拟程序

    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 ...

    SQLAssignment for Chapter 3

    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 ...

    asm.rar_The Show_score board

    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...

    Create a package Vehicles (a sub-directory under the working directory) that holds the

    “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 ...

    辽宁诗港市黑沟中学七年级英语上册Unit1Myname’sGinaSelfcheck课件新版人教新目标版

    4. 记忆单词技巧:记忆单词时可以关联生活场景,比如打电话要拨打 "telephone number",乘坐飞机需要 "ID card",表明自己用 "I am…",打招呼可以用 "Hi/Hello",介绍名字用 "My name is…",他/她的名字则用 "his/...

    USBDeview v1.43 - View all installed/connected USB devices on your system

    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 ...

    USBDeview v1.80[2010最新版]

    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 ...

Global site tag (gtag.js) - Google Analytics