USACO - PROB Your Ride Is Here
本文最后更新于:2021年5月8日 下午
Your Ride Is Here
SAMPLE INPUT (file ride.in)
COMETQ
HVNGAT
OUTPUT FORMAT
“GO” or “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’.
/*
ID: rickyxu1
LANG: C++
PROG: ride
*/
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
using namespace std;
int main() {
ofstream fout ("ride.out");
ifstream fin ("ride.in");
char inpstr1[8],inpstr2[8];
vector<int> vnum1,vnum2;
fin >> inpstr1 >> inpstr2;
for(int i = 0; inpstr1[i] != '\0';i++)
{
int num1 = (int)inpstr1[i] - 'A' + 1;
// cout << "num1:" << num1 << endl;//test output
vnum1.push_back(num1);
}
for(int i = 0; inpstr2[i] != '\0';i++)
{
int num2 = (int)inpstr2[i] - 'A' + 1;
// cout << "num2:"<<num2 << endl;//test output
vnum2.push_back(num2);
}
int sum1 = 1;
for (int j = 0; j < vnum1.size();j++){
sum1 *= vnum1[j];
}
int res1 = sum1 % 47;
int sum2 = 1;
for (int j = 0; j < vnum2.size();j++){
sum2 *= vnum2[j];
}
int res2 = sum2 % 47;
// cout << "res1:"<<res1 << endl;//test output
// cout << "res2:"<<res2 << endl;//test output
if (res1 == res2)
{
fout << "GO" << endl;
}
else
{
fout << "STAY" << endl;
}
return 0;
}
一开始没读懂题,以为是一行一行读的数据,就按照一行的来写了,后来发现不对就直接一式两份,最后判断一下是否相等就输出结果了。
Test 1: TEST OK [0.004 secs, 1348 KB]
Test 2: TEST OK [0.004 secs, 1332 KB]
Test 3: TEST OK [0.004 secs, 1424 KB]
Test 4: TEST OK [0.004 secs, 1408 KB]
Test 5: TEST OK [0.004 secs, 1348 KB]
Test 6: TEST OK [0.004 secs, 1348 KB]
Test 7: TEST OK [0.004 secs, 1404 KB]
Test 8: TEST OK [0.004 secs, 1352 KB]
Test 9: TEST OK [0.004 secs, 1364 KB]
Test 10: TEST OK [0.004 secs, 1364 KB]
本博客所有文章除特别声明外,均采用 CC BY-SA 4.0 协议 ,转载请注明出处!