zoukankan      html  css  js  c++  java
  • USACO 1.2-Name That Number

    /*
    ID: m1590291
    TASK: namenum
    LANG: C++
    */
    /******************************************************************************************************************
            一个字母只对应一个数字,从字典中读入一个单词,把它转化成唯一对应的数字,
            看它是否与给出的数字匹配,
            时间规模是5000*12=6e4,空间规模是常数,而且编程复杂度较低
            还可以先比较字符长度和数字长度,如果相等,逐位比较。
    ******************************************************************************************************************/
    #include <iostream>
    #include <fstream>
    #include <string.h>
    using namespace std;
    string dict[5000],f[5000];
    void fuc()
    {
        char set[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'};
    
        ifstream FIN("dict.txt");
        for(int i=0;i<4617;i++){
            FIN>>dict[i];
            f[i]=dict[i];
        }
        for(int i=0;i<4617;i++){
            for(int j=0;j<dict[i].size();j++)
                f[i][j]=set[f[i][j]-'A'];
        }
        FIN.close();
    }
    int main()
    {
        string s;
        ifstream fin("namenum.in");
        ofstream fout("namenum.out");
        fuc();
        while(fin>>s)
        {
            int flag=0;
            for(int i=0;i<4617;i++)
                if(s == f[i]){
                    fout<<dict[i]<<endl;
                    flag=1;
                }
    
            if(!flag)
                fout<<"NONE"<<endl;
        }
        fin.close();
        fout.close();
        return 0;
    }
    


  • 相关阅读:
    pytorch中的detach和detach_
    matlab求导
    Introduction to the Tcl command language
    Tcl/Tk学习
    利用char, str2mat, strvcat创建多行字符串数组
    矩阵操作
    matlab创建三对角线矩阵
    TensorFlow v2.0的基本张量操作
    数据科学家应知道的关于数据科学项目的四个关键方面
    使用TensorFlow v2库实现线性回归
  • 原文地址:https://www.cnblogs.com/Jstyle-continue/p/6352041.html
Copyright © 2011-2022 走看看