跳至正文

USACO 1.1.1 Your Ride Is Here

  • OI路程

  这一题的话,觉得我的代码函数独立的不错,因为题目毕竟简单,所以也就这么写吧:

/
LANG:C
ID:zqynux2
PROG: ride
/
#include <stdio.h>
#include <string.h>
typedef char string[7];

int get_num(char ch)
{
        return ch – ‘A’ + 1;
}

int change_to_num(string str, int n)
{
        int i, sum = 1;
        int len;
        len = strlen(str);
        for(i = 0; i < len; i++){
                sum *= get_num(str[i]);
                sum %= n;
        }
        return sum;
}

int main(void)
{
        int i, j;
        string team, star;
        freopen("ride.in""r"stdin);
        freopen("ride.out""w"stdout);
        scanf("%s%s", team, star);
        i = change_to_num(team, 47);
        j = change_to_num(star, 47);
        if(i == j){
                printf("GO\n");
        }else{
                printf("STAY\n");
        }
        return 0;
}

发表回复

您的电子邮箱地址不会被公开。