usaco Name That Number

为什么要使用如此反人类的输入方式。

/*
ID: modengd1
PROG: namenum
LANG: C++
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main() {
    FILE *in = fopen ("namenum.in", "r");
    FILE *in2 = fopen ("dict.txt", "r");
    FILE *out = fopen ("namenum.out","w");
    int nsolutions = 0;
    int numlen;
    char input[20];
    char dict[20];
    char map[256];
    int i, j;
    map[‘A‘] = map[‘B‘] = map[‘C‘] = ‘2‘;
    map[‘D‘] = map[‘E‘] = map[‘F‘] = ‘3‘;
    map[‘G‘] = map[‘H‘] = map[‘I‘] = ‘4‘;
    map[‘J‘] = map[‘K‘] = map[‘L‘] = ‘5‘;
    map[‘M‘] = map[‘N‘] = map[‘O‘] = ‘6‘;
    map[‘P‘] = map[‘R‘] = map[‘S‘] = ‘7‘;
    map[‘T‘] = map[‘U‘] = map[‘V‘] = ‘8‘;
    map[‘W‘] = map[‘X‘] = map[‘Y‘] = ‘9‘;
    fscanf(in,"%s",input);
    int l1=strlen(input);
    bool finD=false;
    while(~fscanf(in2,"%s",dict))
    {
        int i;
        int l2=strlen(dict);
        if(l1!=l2)
            continue;
        for( i=0;i<l2;i++)
        {
            if(input[i]!=map[dict[i]])
                break;
        }
        if(i==l2)
        {
            fprintf (out, "%s\n", dict);
            finD=true;
        }
    }
    if(!finD)
        fprintf(out,"NONE\n");
    return 0;
}

  

时间: 2024-11-08 22:27:57

usaco Name That Number的相关文章

USACO 1.5 Number Triangles

Number Triangles Consider the number triangle shown below. Write a program that calculates the highest sum of numbers that can be passed on a route that starts at the top and ends somewhere on the base. Each step can go either diagonally down to the

USACO Name That Number(File)

题目请点我 题解: 题目应该不难理解,就是找出数字对应字典中的字符串.因为数字对字符是一对多的关系,所以输入的数字可能对应多个答案.如果每次都要一一对比查找的话显然太浪费时间.转换思路,对于字典中的字符串,他们都有自己唯一对应的数值,我们只需一次遍历,就能将他们全部转化,剩下的共作就是每次对比数值,输出对应字符串了. PS:这道题在输入上坑了很久,原因在于%I64d 和 %lld ,用%I64d错在第三组,但是%lld是可以的.在网上查的资料也并没有很清楚之间的区别,但是如果用cin的话就不会遇

USACO Section1.5 Number Triangles 解题报告

numtri解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------------------------------------------------------------------------------------------[题目] 有一个数字的金字塔,形状如下    7   3 8  8 1 0 2 7 4 4 4 5 2 6 5 要从顶端开始走,每次只能向

USACO training course Number Triangles 数塔 /// DP oj10122

题目大意: ...就是数塔       7         3   8      8   1   0     2   7   4   4 4   5   2   6   5 7+3+8+7+5=30 Sample Input 573 88 1 02 7 4 44 5 2 6 5 212 3 Sample Output 304 DP水题 记录一下 自下往上走 左右始终选择较大的与之上的相加 #include<iostream> #include<algorithm> #include

USACO Section1.2 Name That Number 解题报告

namenum解题报告 —— icedream61 博客园(转载请注明出处)------------------------------------------------------------------------------------------------------------------------------------------------[题目] 你有一个手机,键盘如下所示: 2: A,B,C 5: J,K,L 8: T,U,V 3: D,E,F 6: M,N,O 9:

USACO 1.2 Name That Number

Name That Number Among the large Wisconsin cattle ranchers, it is customary to brand cows with serial numbers to please the Accounting Department. The cow hands don't appreciate the advantage of this filing system, though, and wish to call the member

usaco Number Triangles

数字三角形,最简单的dp之一. 不过这次尝试了下滚动数组. /* ID: modengd1 PROG: numtri LANG: C++ */ #include <iostream> #include <stdio.h> #include <memory.h> using namespace std; int dp[2][1000],input[1001]; int main() { freopen("numtri.in","r"

【BZOJ】【1662】/【POJ】【3252】 【USACO 2006 Nov】Round Number

数位DP 同上一题Windy数 预处理求个组合数 然后同样的方法,这次是记录一下0和1的个数然后搞搞 Orz cxlove 1 /************************************************************** 2 Problem: 1662 3 User: Tunix 4 Language: C++ 5 Result: Accepted 6 Time:0 ms 7 Memory:1280 kb 8 **************************

【USACO 1.2】Name That Number

给你一串数字(≤12个),每个数字可以对应3个字母,求生成的所有字符串里,在字典内的有哪些. 我做的时候想的是字典树(Trie 树),模拟数串生成的所有字符串,然后在字典树里查找一下. /* TASK:namenum LANG:C++ */ #include <iostream> #include <fstream> #include <algorithm> #include <cstdio> #include <cstring> #define