USACO-Section1.1 Your Ride Is Here [模拟]
来源:互联网 发布:index是什么意思c语言 编辑:程序博客网 时间:2024/06/03 06:19
2017-05-26
题目描述:
输入两个字符串(comet,
group),均由不超过6个的大写英文字符组成。按照字符’A’对应于数值1,字符’B’对应于数值2……以此类推,字符’Z’
对应于数值26。现在把每个字符串的每个字符所对应的数值相乘,如果comet得到的值对47取模的余数和group对47取模的余数相等,则输出”GO”,否则输出”STAY”。通过文件实现数据读写。
题解:
依照题意编程即可。
代码如下:
/*ID: madara01PROG: rideLANG: C++*/#include <iostream>#include <fstream>#include <string>#define cin fin#define cout foutusing namespace std;int main() { //据说可以消除缓冲区提高读写效率 ios::sync_with_stdio(false); ofstream fout ("ride.out"); ifstream fin ("ride.in"); string comet, group; cin >> comet >> group; int cl = 1,gl = 1; int i = 0; for(i = 0; i < comet.length(); i++) { cl *= (comet[i] - 'A' + 1); //每次都对47取余以降低cl很大时的乘法开销 cl %= 47; } for(i = 0; i < group.length(); i++) { gl *= (group[i] - 'A' +1); gl %= 47; } if(cl == gl) { cout << "GO" << endl; }else{ cout << "STAY" << endl; } return 0;}
阅读全文
0 0
- USACO-Section1.1 Your Ride Is Here [模拟]
- USACO-Section1.1 Your Ride Is Here [模拟]
- USACO-Section1.1 Your Ride Is Here
- USACO-Section1.1 Your Ride Is Here
- USACO-Section1.1 Your Ride Is Here
- USACO Section1.1 Your Ride Is Here
- [USACO] Section1.1 Your Ride Is Here[字符串处理]
- [USACO] Section1.1 Your Ride Is Here[字符串处理]
- USCAO-Section1.1 Your Ride Is Here
- Your Ride Is Here-section1.1
- Section1.1-Your Ride Is Here
- USACO之Section1.1.1 Your Ride Is Here
- USACO 1.1.1 Your Ride Is Here
- [USACO 1.1.1] Your Ride Is Here
- USACO 1.1.1 Your Ride Is Here
- USACO 1.1.1 Your Ride Is Here
- USACO 1.1.1 Your Ride Is Here
- USACO 1.1.1 Your Ride Is Here
- awk
- QT学习笔记(4)对话框(1)
- ajax跨域问题(三种解决方案)
- File 输入输出流
- Spring 事务管理总结
- USACO-Section1.1 Your Ride Is Here [模拟]
- 【分治法】最接近点对问题——Java 实现
- DFS与BFS的区别、用法、详解?
- 终于把资料填完了
- Nexus6刷机前未注销谷歌账号,刷机后wifi无法通过shadowsocks局域网共享联网验证处理办法
- POJ-1915 Knight Moves
- JS基础 jQuery下AJAX请求
- linux php 安装redis 扩展
- LeetCode Merge k Sorted Lists(分治法)