Section 1.2.3 Name That Number 水
2015-07-08 22:42
435 查看
题意: http://www.wzoi.org/usaco/11%5C206.asp
解法:
貌似解法是多种多样的
我的方法是,将字典里所有字母转为数字,然后检查是不是和输入相同
patpat
View Code
解法:
貌似解法是多种多样的
我的方法是,将字典里所有字母转为数字,然后检查是不是和输入相同
patpat
#include <bits/stdc++.h> using namespace std; typedef long long ll; ll trans(string name){ int len = name.length(), i; ll val = 0ll; for(i = 0; i < len; i++){ if(name[i] < 'Q')val = val * 10 + (name[i] - 'A')/ 3 + 2; else { val = val * 10 + (name[i] - 'A' - 1) / 3 + 2; } } return val; } int main() { ifstream fin("namenum.in"); ifstream dict("dict.txt"); #ifndef poi ofstream fout("namenum.out"); #endif ll inp; fin >> inp; string name; bool gg = true; while(dict>>name){ // cout<< name <<" "<<trans(name) <<endl; if(inp != trans(name)) continue; gg = false; fout<<name<<endl; } if(gg) fout<<"NONE"<<endl; dict.close();; fin.close(); #ifndef poi fout.close(); #endif return 0; }
View Code
相关文章推荐
- 第十五章 单点登录——《跟我学Shiro》
- logback配置日志文件
- 【Android 应用开发】 自定义组件 宽高适配方法, 手势监听器操作组件, 回调接口维护策略, 绘制方法分析 -- 基于 WheelView 组件分析自定义组件
- 图文解释XCode常用快捷键的使用
- LV的几种适配器特点
- Gas Station
- html5本地存储
- 6.1-2
- 如何应对SparkSQL DataFrame保存到hdfs时出现的过多小文件问题
- com.example.firstservice.FirstService cannot be cast to android.app.Activity
- 消除启动欢迎页时的黑屏问题
- java创建文件,并向文件中写入字符串,读取字符串到屏幕
- Swing-BoxLayout用法-入门
- OpenGL 2.0编程例子
- 关于IO时延你被骗了多久?
- Set Matrix Zeros
- 使用读写锁解决读者-写者问题
- 读《30年后,你拿什么养活自己?》有感
- LeetCode 33, Search in Rotated Sorted Array-----Binary Search
- 搬家了。