USACO-Section1.1 Your Ride Is Here
来源:互联网 发布:三公棋牌软件 编辑:程序博客网 时间:2024/06/07 14:23
2017-5-25
题目大意:
输入两个长度为1到6的字符串str1和str2(均是由大写字母构成),其中"A"是1、"B"是2 ···· "Z"是26。例如,“USACO”小组就是21*19*1*3*15=17955。如果str1和str2所求得的上述值模47的结果相同,则输出"GO",否则输出"STAY"
题解:
分别将两个字符串的每个字符减去64(或者减去'A'再加1)然后对应相乘,再对47求余即可。
代码:
#include<iostream> #include<cstring> #include<fstream> using namespace std; int main(){ ofstream fout("ride.out"); ifstream fin("ride.in"); char ch1[10],ch2[10]; int a[10],b[10]; int sum1 = 1, sum2 = 1; fin >> ch1 >> ch2; for(int i = 0;i < strlen(ch1);i++){ a[i] = ch1[i] - 'A' + 1; sum1 = (sum1 * a[i] % 47); } for(int i = 0;i < strlen(ch2);i++){ b[i] = ch2[i] - 'A' + 1; sum2 = (sum2 * b[i] % 47); } if(sum1 == sum2){ fout << "GO" << endl; } else{ fout << "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
- 第一讲 MyBatis开端
- qduoj 140 题目6 142 ycb的ACM进阶之路
- MVC结构简介
- Kali渗透测试——UPNP网关发现工具Miranda
- python爬虫2-简单模拟用户登录
- USACO-Section1.1 Your Ride Is Here
- 第二讲 CRUD操作
- mysql 通过limit分页 oracle通过ruwnum来分页 语句如下
- Visual SLAM Introduction In Detail
- Castle 整合.NET Remoting
- 大端与小端存储模式详解
- 第三讲 配置文件解析
- 我为何需要使用空接口?
- Html.fromHtml利用Textview显示html文本