USACO Your Ride Is Here ——水题

May 21, 2013
USACO

题目链接:http://cerberus.delos.com:790/usacoprob2?a=nR34fDHld4J&S=ride 人家说USACO的题目适合入门……我还是先刷这个吧…… 这道题目主要是学了一下USACO里面的文件输入输出格式


/*
ID: zypz457
TASK: ride
LANG: C++
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <fstream>
using namespace std;
int main(void) {
  ifstream fin("ride.in");
  ofstream fout ("ride.out");
  char a[10], b[10];
  while (fin >> a >> b) {
    int sum1, sum2, i, len1, len2;
    len1 = strlen(a); len2 = strlen(b);
    sum1 = sum2 = 1;
    for (i = 0; i < len1; ++i) {
      sum1 = (sum1*(a[i]-'A'+1))%47;
    }
    for (i = 0; i < len2; ++i) {
      sum2 = (sum2*(b[i]-'A'+1))%47;
    }
    /*  
    if (sum1 == sum2) fprintf(fout, "GO\n");
    else fprintf(fout, "STAY\n");
     *  */
    if(sum1 == sum2) fout << "GO\n";
    else fout << "STAY\n";
  }
  return 0;
}

不用每次交题目都复制了倒是……但是格式要求挺严格的……还要有注释。。。 好吧,读文件神马的不用那么麻烦……按照原来的习惯写就行。  


/*
ID: zypz457
TASK: ride
LANG: C++
*/
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;
int main(void) {
  freopen("ride.in", "r", stdin);
  freopen("ride.out", "w", stdout);
  char a[10], b[10];
  while (~scanf("%s%s",a, b)) {
    int sum1, sum2, i, len1, len2;
    len1 = strlen(a); len2 = strlen(b);
    sum1 = sum2 = 1;
    for (i = 0; i < len1; ++i) {
      sum1 = (sum1*(a[i]-'A'+1))%47;
    }
    for (i = 0; i < len2; ++i) {
      sum2 = (sum2*(b[i]-'A'+1))%47;
    }
    if (sum1 == sum2) printf("GO\n");
    else printf("STAY\n");
  }
  return 0;
}

  谢谢fray    

comments powered by Disqus