USASO Section1.1Your Ride Is Here[其他]
来源:互联网 发布:卖家怎么加入淘宝直播 编辑:程序博客网 时间:2024/06/06 01:42
2017.5.18
题目:
输入两个由大写字母组成的字符串,A~Z分别转换为1~26,然后将其累乘,得到的两个乘积如果mod 47后相等则输出GO,否则输出STAY
SAMPLE INPUT (file ride.in)#
COMETQ
HVNGAT
OUTPUT FORMAT
A single line containing either the word “GO” or the word “STAY”.
SAMPLE OUTPUT (file ride.out)
GO
OUTPUT EXPLANATION
Converting the letters to numbers:
C O M E T Q
3 15 13 5 20 17
H V N G A T
8 22 14 7 1 20
then calculate the product mod 47:
3 * 15 * 13 * 5 * 20 * 17 = 994500 mod 47 = 27
8 * 22 * 14 * 7 * 1 * 20 = 344960 mod 47 = 27
Because both products evaluate to 27 (when modded by 47), the mission is ‘GO’.
题解:
乘积的取余等于取余的乘积,由此可以避免数据溢出。注意ASCII码和字符之间的转换,表内字符可以直接作为整数来计算,减去64即可。
代码:
/*ID: xcwhkh1LANG: CTASK: ride*/#include <stdio.h>char a[100002];char b[100002];int main () { FILE *fin = fopen ("ride.in", "r"); FILE *fout = fopen ("ride.out", "w"); fscanf (fin, "%s\n%s",a,b); /* the two input integers */ int sa=1,sb=1,i; for(i=0;a[i]!='\0';i++) sa=sa*(a[i]-64)%47; for(i=0;b[i]!='\0';i++) sb=sb*(b[i]-64)%47; if(sa!=sb) fprintf (fout,"STAY\n"); else fprintf (fout,"GO\n"); return 0;}
阅读全文
0 0
- USASO Section1.1Your 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
- USACO Section1.1 Your Ride Is Here
- 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.1 Your Ride Is Here
- Your Ride Is Here
- Your Ride Is Here
- Your Ride Is Here
- your ride is here
- Your Ride Is Here
- 收集EVA日志和配置信息
- HotSpot虚拟机对象的创建、存储和定位
- 考研数学笔记 16~20
- 数据仓库A
- my_shell的简单实现
- USASO Section1.1Your Ride Is Here[其他]
- 整数排序
- Excel合并多个工作表(Sheet)到一个Sheet中脚本
- 饥饿与活锁
- 深入理解javascript原型和闭包(3)——prototype原型
- Brocade HP SAN 交换机产品对应表
- python 命令行版todolist
- 内存溢出和内存泄露分析
- 位运算符