UVa12195 - Jingle Composing(strtok的使用)

来源:互联网 发布:圣象地板 知乎 编辑:程序博客网 时间:2024/06/06 00:38

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:

\epsfbox{p4481.eps}

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
题意:给出一行字符串,求出两个斜杠之间的字母之和是否等于1,统计个数

思路:注意用浮点数精确度的问题,在这里用W=64,H=32, Q=16, E=8, S=4, T=2, X=1,计算两斜杠之间的数字之和,看是否等于64

#include <cstdio>#include <cstring>#include <map>using namespace std;const int MAXN = 210;char str[MAXN];int cal(char ch){    switch (ch) {        case 'W': return 64;        case 'H': return 32;        case 'Q': return 16;        case 'E': return 8;        case 'S': return 4;        case 'T': return 2;        case 'X': return 1;    }}bool input() {    scanf("%s", str);    if (strcmp(str, "*") == 0) return false;        return true;}void solve() {    char *p = strtok(str, "/");    int ans = 0;        while (p) {        int sum = 0;        for (int i = 0, len = strlen(p); i < len; i++) {            sum += cal(p[i]);        }        //printf("sum=%lf\n", sum);        if (sum == 64) ans++;        p = strtok(NULL, "/");    }        printf("%d\n", ans);}int main() {#ifndef ONLINE_JUDGE    freopen("/cygdrive/d/OJ/uva_in.txt", "r", stdin);#endif    while (input()) {        solve();    }    return 0;}




0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 学生去新加坡旅游签证怎么办 出入境的受理编号不见了怎么办 职工下岗档案单位丢失怎么办退休 大学毕业档案在自己手里怎么办 青岛李沧区房产证加名字怎么办手续 公积金迟交了1天怎么办 科一预约不上怎么办 科目一考试没去怎么办 科目一成绩单丢了怎么办 考科目二身份证丢了怎么办 考科目三身份证丢了怎么办 考科目一身份证丢了怎么办 滴滴顺风车被永久封禁怎么办 三岁宝宝智力发育迟缓怎么办 学车体检听力没过怎么办 学车体检听力不过关怎么办 离职体检发现听力有问题怎么办 买的二手房土地证没过户怎么办 b2扣了9分怎么办 上海网约车车证怎么办 b2驾照累计12分怎么办 c1本扣满12分怎么办 太原公共自行车丢了怎么办 在太原出租车丢了东西怎么办 太原社保卡丢了怎么办 太原铁路医保卡丢了怎么办 学车体检视力不合格怎么办 换驾照色弱被拒怎么办 在上海考驾照贵怎么办 驾驶证有效期过了半年怎么办 资格证脱审2年了怎么办 换驾驶证时眼睛近视了怎么办 违章累计扣12分怎么办 一个违章扣12分怎么办 a1驾照扣3分怎么办 a1驾照扣12分怎么办 吃了毓婷哺乳了怎么办 吃了毓婷后出血怎么办 吃金毓婷喝了水怎么办 白带浓稠浆糊样怎么办 驾校学费不给退怎么办