记录编号 |
118536 |
评测结果 |
AAAAA |
题目名称 |
[GZOI2011] 乐谱变调 |
最终得分 |
100 |
用户昵称 |
Bokjan |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.001 s |
提交时间 |
2014-09-07 17:39:29 |
内存使用 |
0.29 MiB |
显示代码纯文本
#include <cstdio>
const int maxlen = 200 + 4;
char str[maxlen] = {0};
int data[maxlen] = {0}, dataPtr = 0;
int n = 0, len = -1, curLvl = 0;
const char mapping[][3] = {"",
"C", "#C", "D", "#D",
"E", "F", "#F", "G",
"#G" ,"A", "#A", "B"
};
FILE *io = fopen("music.in", "r");
int strlen(const char *_Str)
{
int _ret = 0;
while(0 != *_Str){
++_ret;
++_Str;
}
return _ret;
}
void transform(void)
{
int len = strlen(str);
for(int i = 0; i != len; ++i)
switch(str[i]){
case 'C':
data[dataPtr++] += 12 * curLvl + 1;
break;
case 'D':
data[dataPtr++] += 12 * curLvl + 3;
break;
case 'E':
data[dataPtr++] += 12 * curLvl + 5;
break;
case 'F':
data[dataPtr++] += 12 * curLvl + 6;
break;
case 'G':
data[dataPtr++] += 12 * curLvl + 8;
break;
case 'A':
data[dataPtr++] += 12 * curLvl + 10;
break;
case 'B':
data[dataPtr++] += 12 * curLvl + 12;
break;
case '#':
++data[dataPtr];
break;
case '>':
++curLvl;
break;
case '<':
--curLvl;
break;
}
curLvl = 0;
}
void modClone(int *clone, int start, bool plus)
{
if(plus)
for(int i = start; i != dataPtr; ++i)
clone[i] += 12;
else
for(int i = start; i != dataPtr; ++i)
clone[i] -= 12;
}
void work(void)
{
int clone[maxlen] = {0};
for(int i = 0; i != dataPtr; ++i){
data[i] += n;
clone[i] = data[i];
}
for(int i = 0; i != dataPtr; ++i){
while(data[i] > curLvl * 12 + 12){
modClone(clone, i, false);
++curLvl;
fprintf(io, ">");
}
while(data[i] < curLvl * 12 + 1){
modClone(clone, i, true);
--curLvl;
fprintf(io, "<");
}
fprintf(io, "%s", mapping[clone[i]]);
}
}
int main(void)
{
fscanf(io, "%s", str);
fscanf(io, "%d", &n);
fclose(io);
transform();
io = fopen("music.out", "w");
work();
fclose(io);
return 0;
}