zoukankan      html  css  js  c++  java
  • USACO Your Ride Is Here ——水题

    题目链接:http://cerberus.delos.com:790/usacoprob2?a=nR34fDHld4J&S=ride

    人家说USACO的题目适合入门……我还是先刷这个吧……

    这道题目主要是学了一下USACO里面的文件输入输出格式

     1 /*
     2 ID: zypz457
     3 TASK: ride
     4 LANG: C++
     5 */
     6 #include <cstdio>
     7 #include <cstdlib>
     8 #include <cstring>
     9 #include <fstream>
    10 using namespace std;
    11 int main(void) {
    12   ifstream fin("ride.in");
    13   ofstream fout ("ride.out");
    14   char a[10], b[10];
    15   while (fin >> a >> b) {
    16     int sum1, sum2, i, len1, len2;
    17     len1 = strlen(a); len2 = strlen(b);
    18     sum1 = sum2 = 1;
    19     for (i = 0; i < len1; ++i) {
    20       sum1 = (sum1*(a[i]-'A'+1))%47;
    21     }
    22     for (i = 0; i < len2; ++i) {
    23       sum2 = (sum2*(b[i]-'A'+1))%47;
    24     }
    25     /*  
    26     if (sum1 == sum2) fprintf(fout, "GO\n");
    27     else fprintf(fout, "STAY\n");
    28      *  */
    29     if(sum1 == sum2) fout << "GO\n";
    30     else fout << "STAY\n";
    31   }
    32   return 0;
    33 }

    不用每次交题目都复制了倒是……但是格式要求挺严格的……还要有注释。。。

    好吧,读文件神马的不用那么麻烦……按照原来的习惯写就行。

     1 /*
     2 ID: zypz457
     3 TASK: ride
     4 LANG: C++
     5 */
     6 #include <cstdio>
     7 #include <cstdlib>
     8 #include <cstring>
     9 using namespace std;
    10 int main(void) {
    11   freopen("ride.in", "r", stdin);
    12   freopen("ride.out", "w", stdout);
    13   char a[10], b[10];
    14   while (~scanf("%s%s",a, b)) {
    15     int sum1, sum2, i, len1, len2;
    16     len1 = strlen(a); len2 = strlen(b);
    17     sum1 = sum2 = 1;
    18     for (i = 0; i < len1; ++i) {
    19       sum1 = (sum1*(a[i]-'A'+1))%47;
    20     }
    21     for (i = 0; i < len2; ++i) {
    22       sum2 = (sum2*(b[i]-'A'+1))%47;
    23     }
    24     if (sum1 == sum2) printf("GO\n");
    25     else printf("STAY\n");
    26   }
    27   return 0;
    28 }

    谢谢fray

  • 相关阅读:
    Philosophy is systematic reflective thinking on life.
    HashMap与HashTable的区别、HashMap与HashSet的关系
    android Intent机制详解
    Android Parcelable理解与使用(对象序列化)
    Java并发编程:volatile关键字解析
    JavaEE 对象的串行化(Serialization)
    pytorch学习
    numpy的一些用法
    约瑟夫问题
    双向链表及其操作
  • 原文地址:https://www.cnblogs.com/liuxueyang/p/3090449.html
Copyright © 2011-2022 走看看