跳到正文

题解

题解 P3864 【[USACO1.2]命名那个数字 Name That Number】

jinhaoxian约 1 分钟
原文
文章信息与版本

文章信息

发布
2018年8月11日
收录
2025年12月12日
更新
2026年11月11日
篇幅
约 1 分钟
题目
P3864

版本

  1. v1当前

本题我的基本思路是:依次读入这些名字,一个一个转化为数字判断是否与读入的数字相等。

C++
#include<bits/stdc++.h>
using namespace std;
int i;
bool f=false;
long long m;//12位int不够
string st;
long long name(string s)
{
    long long n=0;
    for (int i=0;i<s.size();i++)
    if (s[i]<='P') n=n*10+(s[i]-59)/3;
    else n=n*10+(s[i]-60)/3;//我写的转化为数字的语句,希望大家能看懂
    return n;
}
int main()
{
    cin>>m;//读入数字
    for (i=1;i<=4617;i++)//依次读入名字
    {
        cin>>st;
        if (name(st)==m) //转换为数字判断
        {
            cout<<st<<endl;
            f=true;
        }
    }
    if (f==false) cout<<"NONE"<<endl;//如果没有输出NONE
    return 0;
}
原文