`
kalviny
  • 浏览: 5353 次
  • 性别: 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)及代码解析

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

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

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

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

    Address Book with Multiple Field Search(个人信息管理系统)

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

    Geek Challenge [SKRZAT]

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

    闭包搜索算法java编程

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

    强大的USB 查看工具,绝对不是USBView

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

    pricinples of communication system simulation with wireless aplications

    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.

    VB.NET多款风格渐变和无规则按钮

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

    Student Assessment Reporting System

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

Global site tag (gtag.js) - Google Analytics