| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 420 人关注过本帖
标题:好纠结啊,到底哪错了
只看楼主 加入收藏
编程探索者
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2010-7-21
结帖率:100%
收藏
 问题点数:0 回复次数:1 
好纠结啊,到底哪错了
题目是这样的;
Problem description
A. C. Marcos is taking his first steps in the direction of jingle composition. He is having some troubles, but at least he is achieving pleasant melodies and attractive rhythms.
In music, a note has a pitch (its frequency, resulting in how high or low is the sound) and a duration (for how long the note should sound). In this problem we are interested only in the duration of the notes.
A jingle is divided into a sequence of measures, and a measure is formed by a series of notes. The duration of a note is indicated by its shape. In this problem, we will use uppercase letters to indicate a note's duration. The following table lists all the available notes:



The duration of a measure is the sum of the durations of its notes. In Marcos' jingles, each measure has the same duration. As Marcos is just a beginner, his famous teacher Johann Sebastian III taught him that the duration of a measure must always be 1.
For example, Marcos wrote a composition containing five measures, of which the first four have the correct duration and the last one is wrong. In the example below, each measure is surrounded with slashes and each note is represented as in the table above.

/HH/QQQQ/XXXTXTEQH/W/HW/

Marcos likes computers as much as music. He wants you to write a program that determines, for each one of his compositions, how many measures have the right duration.


 
Input
The input contains several test cases. Each test case is described in a single line containing a string whose length is between 3 and 200 characters, inclusive, representing a composition. A composition begins and ends with a slash '/'. Measures in a composition are separated by a slash '/'. Each note in a measure is represented by the corresponding uppercase letter, as described above. You may assume that each composition contains at least one measure and that each measure contains at least one note. All characters in the input will be either slashes or one of the seven uppercase letters used to represent notes, as described above.
The last test case is followed by a line containing a single asterisk.


 
Output
For each test case your program must output a single line, containing a single integer, the number of measures that have the right duration.

 
Sample Input
/HH/QQQQ/XXXTXTEQH/W/HW/
/W/W/SQHES/
/WE/TEX/THES/
*
 
Sample Output
4
3
0
 
搜索更多相关主题的帖子: 纠结 
2010-07-25 17:48
编程探索者
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2010-7-21
收藏
得分:0 
代码写成了这样
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{   
   
    char str[3000],a[10]="*";
    int N,l,i,flag=0,sum;
   
   
     while(scanf("%s",str)!=EOF)
     {
     if(strcmp(str,a)==0)
       break;
      else
      {
      l=strlen(str);
      flag=0;
      sum=0;
      
      for(i=1;i<l;i++)
        {  
           
           if(str[i]=='W')
             sum=sum+64;
           else
              if(str[i]=='H')
                sum=sum+32;
              else
                 if(str[i]=='Q')
                    sum=sum+16;   
                 else
                     if(str[i]=='E')
                       sum=sum+8;
                     else
                     if(str[i]=='S')
                        sum=sum+4;
                     else
                        if(str[i]=='T')
                           sum=sum+2;
                        else
                           if(str[i]=='X')
                             sum=sum+1;
                           if(str[i]=='/')
                           {
                               if(sum%64==0)
                               {
                                sum=0;
                                flag++;
                               }
                               else
                                 break;
                           
                          }
                       
            }
      
          printf("%d\n",flag);  
          }
       }
        
    return 0;
}
2010-07-25 17:49
快速回复:好纠结啊,到底哪错了
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015198 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved