现在的位置: 首页 > 综合 > 正文

USACO 1.1 Problem 1

2017年11月21日 ⁄ 综合 ⁄ 共 547字 ⁄ 字号 评论关闭

Problem 1

Your Ride is here

题目描述:读入两个字符串,将A看成1,将Z看成26之后乘起来mod47,如果两个串得到的结果一样输出GO,如果不一样输出STAY。

要点:字符处理是减去64得到数字。

我当时做的时候把初始值设为0了...这样会使结果全部为0没有变化,跪了。

代码如下:

#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
	ofstream fout("ride.out");
	ifstream fin("ride.in");
	string s1, s2;
	fin >> s1 >> s2;
	int result1 = 1;
	int result2 = 1;
	for (int i = 0; i < s1.length(); ++i) {
		result1 *= (s1[i]-64);
		if (result1 >= 47) result1 %= 47;
	}
	for (int i = 0; i < s2.length(); ++i) {
		result2 *= (s2[i]-64);
		if (result2 >= 47) result2 %= 47;
	}
	if (result1 == result2) fout << "GO" << endl;
	else fout << "STAY" << endl;
	
	return 0;
}
【上篇】
【下篇】

抱歉!评论已关闭.