首页 > ACM题库 > HDU-杭电 > hdu 2630 Watch Channel[V][解题报告]hoj
2014
02-12

hdu 2630 Watch Channel[V][解题报告]hoj

Watch Channel[V]

问题描述 :

When talking about entertainment,Samuel prefers listening to music than anything else. Of all the Chinese singers,Samuel mostly enjoys the songs of Taiwan girl band S.H.E.
Do you have any likes and dislikes in choosing whose songs to enjoy?And Samuel is fond of watching Channel[V].But Samuel has a bad habit. When the singer does not match his taste,he will immediately switch the channel.
Samuel likes S.H.E,Jay,Elva,Jolin,Aska,and Yoga(Pay more attention to the spelling please!Use them according to what Samuel gives you or you may get wrong answer). Suppose Samuel don’t like any other singers., you are asked to tell how long will Samuel stay in front of the TV according to a list of the MVs that are planned to be broadcast in Channel[V].

输入:

The input will be 2 part:
the first line only contain a number t,which means the number of test cases. The first line of each test case will be the n MVs that will be broadcast,and each of the following n lines will be the MV’s singer and each of the MV will take MM:SS time.

输出:

The input will be 2 part:
the first line only contain a number t,which means the number of test cases. The first line of each test case will be the n MVs that will be broadcast,and each of the following n lines will be the MV’s singer and each of the MV will take MM:SS time.

样例输入:

1
3
S.H.E 03:40
Jay  04:50
Elva 05:35

样例输出:

Samuel will watch Channel[V] for 0 hour(s),14 minute(s),5 second(s).

#include<stdio.h>
#include<string.h>
char a[7][40];
int main()
{
int t,i,j,c,n,d,h,m,s;
char b[50];
strcpy(a[0],"S.H.E");
strcpy(a[1],"Jay");
strcpy(a[2],"Elva");
strcpy(a[3],"Jolin");
strcpy(a[4],"Aska");
strcpy(a[5],"Yoga");
scanf("%d",&t);
while(t--)
{
h=m=s=0;
scanf("%d",&n);
getchar();
while(n--)
{
memset(b,'\0',sizeof(b));
scanf("%s %d:%d",b,&c,&d);
getchar();
for(i=0;i<=5;i++)
{
if(strcmp(b,a[i])==0)
{
s=s+d;
if(s>=60)
{
s=s-60;m++;
if(m>=60){m=m-60;h++;}
}
m+=c;
if(m>=60){m=m-60;h++;}
break;
}
}
}
printf("Samuel will watch Channel[V] for %d hour(s),%d minute(s),%d second(s).\n",h,m,s);
}
return 0;
}

  1. /*
    * =====================================================================================
    *
    * Filename: 1366.cc
    *
    * Description:
    *
    * Version: 1.0
    * Created: 2014年01月06日 14时52分14秒
    * Revision: none
    * Compiler: gcc
    *
    * Author: Wenxian Ni (Hello World~), [email protected]
    * Organization: AMS/ICT
    *
    * =====================================================================================
    */

    #include
    #include

    using namespace std;

    int main()
    {
    stack st;
    int n,i,j;
    int test;
    int a[100001];
    int b[100001];
    while(cin>>n)
    {
    for(i=1;i>a[i];
    for(i=1;i>b[i];
    //st.clear();
    while(!st.empty())
    st.pop();
    i = 1;
    j = 1;

    while(in)
    break;
    }
    while(!st.empty()&&st.top()==b[j])
    {
    st.pop();
    j++;
    }
    }
    if(st.empty())
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    }
    return 0;
    }

  2. 我还有个问题想请教一下,就是感觉对于新手来说,递归理解起来有些困难,不知有没有什么好的方法或者什么好的建议?