zoukankan      html  css  js  c++  java
  • USACO1.1.1Your Ride Is Here

    Your Ride Is Here

    It is a well-known fact that behind every good comet is a UFO. These UFOs often come to collect loyal supporters from here on Earth. Unfortunately, they only have room to pick up one group of followers on each trip. They do, however, let the groups know ahead of time which will be picked up for each comet by a clever scheme: they pick a name for the comet which, along with the name of the group, can be used to determine if it is a particular group's turn to go (who do you think names the comets?). The details of the matching scheme are given below; your job is to write a program which takes the names of a group and a comet and then determines whether the group should go with the UFO behind that comet.

    Both the name of the group and the name of the comet are converted into a number in the following manner: the final number is just the product of all the letters in the name, where "A" is 1 and "Z" is 26. For instance, the group "USACO" would be 21 * 19 * 1 * 3 * 15 = 17955. If the group's number mod 47 is the same as the comet's number mod 47, then you need to tell the group to get ready! (Remember that "a mod b" is the remainder left over after dividing a by b; 34 mod 10 is 4.)

    Write a program which reads in the name of the comet and the name of the group and figures out whether according to the above scheme the names are a match, printing "GO" if they match and "STAY" if not. The names of the groups and the comets will be a string of capital letters with no spaces or punctuation, up to 6 characters long.

    Examples:

    Input Output
    COMETQ
    HVNGAT
    
    GO
    ABSTAR
    USACO 
    STAY

    PROGRAM NAME: ride

    This means that you fill in your header with:
    PROG: ride

    INPUT FORMAT

    Line 1: An upper case character string of length 1..6 that is the name of the comet.
    Line 2: An upper case character string of length 1..6 that is the name of the group.

    NOTE: The input file has a newline at the end of each line but does not have a "return". Sometimes, programmers code for the Windows paradigm of "return" followed by "newline"; don't do that! Use simple input routines like "readln" (for Pascal) and, for C/C++, "fscanf" and "fid>>string".

    SAMPLE INPUT (file ride.in)

    COMETQ
    HVNGAT
    

    OUTPUT FORMAT

    A single line containing either the word "GO" or the word "STAY".

    SAMPLE OUTPUT (file ride.out)

    GO

    Solution:纯模拟啊,简单字符串处理,这里就不多说了。
    View Code
     1 /*
     2 ID:spcjv51
     3 PROG:ride
     4 LANG:C
     5 */
     6 #include<stdio.h>
     7 #include<string.h>
     8 int main(void)
     9 {
    10     FILE *fin=fopen("ride.in","r");
    11     FILE *fout=fopen("ride.out","w");
    12     char comet[7],group[7];
    13     int c=1,g=1;
    14     int i,len;
    15     fscanf(fin,"%s %s",comet,group);
    16     len=strlen(comet);
    17     for(i=0; i<len; i++)
    18         c*=(comet[i]-64);
    19     len=strlen(group);
    20     for(i=0; i<len; i++)
    21         g*=(group[i]-64);
    22     if(c%47==g%47)
    23         fprintf(fout,"GO\n");
    24     else
    25         fprintf(fout,"STAY\n");
    26     return 0;
    27 }
    
    
    


    Your Ride Is Here
    TASK: ride
    LANG: C
    Compiling...
    Compile: OK
    
    Executing...
       Test 1: TEST OK [0.000 secs, 2144 KB]
       Test 2: TEST OK [0.000 secs, 2144 KB]
       Test 3: TEST OK [0.000 secs, 2144 KB]
       Test 4: TEST OK [0.000 secs, 2144 KB]
       Test 5: TEST OK [0.000 secs, 2144 KB]
       Test 6: TEST OK [0.000 secs, 2144 KB]
       Test 7: TEST OK [0.000 secs, 2144 KB]
       Test 8: TEST OK [0.000 secs, 2144 KB]
       Test 9: TEST OK [0.000 secs, 2144 KB]
       Test 10: TEST OK [0.000 secs, 2144 KB]
    
    All tests OK.

    Your program ('ride') produced all correct answers! This is your submission #3 for this problem. Congratulations!

    Here are the test data inputs:

    ------- test 1 ----
    COMETQ
    HVNGAT
    ------- test 2 ----
    STARAB
    USACO
    ------- test 3 ----
    EARTH
    LEFTB
    ------- test 4 ----
    PULSAR
    VENUS
    ------- test 5 ----
    KANSAS
    UTAH
    ------- test 6 ----
    APPLE
    URSA
    ------- test 7 ----
    MSFT
    MARS
    ------- test 8 ----
    PLUTO
    BKHOLE
    ------- test 9 ----
    COWSBC
    RIGHT
    ------- test 10 ----
    DRKMTR
    SNIKER
  • 相关阅读:
    动态网络社团检测学习笔记 --- 随机块模型小结之简介
    十五组第四次作业
    17现代软件工程十五组第二次作业
    17现代软件工程十五组第三次作业
    现代软件工程2017十五组成员介绍
    软件测试学习日志3 ————软件测试作业之控制流图
    软件测试学习日志———— round 2 Junit+intellj idea 安装及简单的测试使用
    软件测试学习日志————round 1 some questions of two small programs
    [关于printPrime是()方法的控制流图和点覆盖、边覆盖、主路径覆盖]
    【在myeclipse中使用Junit(4.12), Hamcrest(1.3) 和Eclemma】
  • 原文地址:https://www.cnblogs.com/zjbztianya/p/2822938.html
Copyright © 2011-2022 走看看