Home > Old Blog Posts > USACO 1.1.1 Your Ride Is Here

USACO 1.1.1 Your Ride Is Here


直接模拟即可。

可以加的优化:

读入时采取逐个字符读入,节省存储空间;

求模时使用公式 (a * b) mod c = ((a mod c) * b ) mod c

代码:

/*
ID: dementr1
PROG: ride
LANG: C++
*/
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin(“ride.in”);
ofstream fout(“ride.out”);
int main()
{
int i=1,j=1,k;
string a,b;
fin>>a>>b;
for(k=0;k<a.length();k++) i*=(a[k]-‘A’+1);
for(k=0;k<b.length();k++) j*=(b[k]-‘A’+1);
if(i%47==j%47) fout<<“GO”<<endl;
else fout<<“STAY”<<endl;
return 0;
}

Categories: Old Blog Posts
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: