首页 > 其他 > 详细

URAL 1612. Tram Forum(字符串啊 )

时间:2015-03-20 23:52:44      阅读:569      评论:0      收藏:0      [点我收藏+]

题目链接:http://acm.timus.ru/problem.aspx?space=1&num=1612


1612. Tram Forum

Time limit: 0.5 second
Memory limit: 64 MB
Tram, trolleybus, and bus drivers talk at the tram forum. We have read all messages posted at the forum during last month and discovered an interesting rule. Users in whose messages the word “tram” occurs more often than the word “trolleybus” are tram drivers. Similarly, users in whose messages the word “trolleybus” is more frequent than the word “tram” are trolleybus drivers. All other users of the tram forum are bus drivers. Given this information, can you determine who has posted the latest message at the tram forum?

Input

You are given the latest message at the tram forum. The message consists of lowercase English letters, spaces, line breaks, and punctuation marks: periods, commas, dashes, colons, and exclamation and question marks. The total length of the message is at most 10000 symbols. Words consist of letters and can be separated by spaces, line breaks, and punctuation marks.

Output

Output “Tram driver” if the user who has posted the latest message is a tram driver; output “Trolleybus driver” if she is a trolleybus driver; and output “Bus driver” if she is a bus driver.

Samples

input output
of course, tram is the best transport
in the world!
Tram driver
yes, yekaterinburg trams are the
best trams in the world, but
i like my trolleybus too.
Trolleybus driver
read forum.tr.ru every day!
you can learn much about tram 
drivers and trolleybus drivers.
Bus driver



代码如下:

#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
char s[10047];
int judge(char c)
{
    if(c >= 'a' && c <= 'z')
    {
        return 1;
    }
    return 0;
}
int main()
{
    char s1[17];
    int a = 0, b = 0;
    while(~scanf("%s",&s))
    {
        memset(s1, '\0',sizeof(s1));
        int len = strlen(s);
        for(int i = 0; i < len; i++)
        {
            if(!judge(s[i]))
            {
                continue;
            }
            int k = 0;
            while(judge(s[i]))
            {
                s1[k++] = s[i];
                i++;
            }
            if(strcmp(s1, "tram") == 0)
            {
                a++;
            }
            if(strcmp(s1, "trolleybus") == 0)
            {
                b++;
            }
        }
    }
    //printf("a:%d b:%d\n",a,b);
    if(a > b)
    {
        printf("Tram driver\n");
    }
    else if(a < b)
    {
        printf("Trolleybus driver\n");
    }
    else
    {
        printf("Bus driver\n");
    }
    return 0;
}


URAL 1612. Tram Forum(字符串啊 )

原文:http://blog.csdn.net/u012860063/article/details/44498153

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!