Problem Description
Problem Analysis
Actually, this is a problem from HDU
But since I first saw it on NYOJ, I’ll put it here~
This problem is based on
| A | A#=Bb | B | C | C#=Db | D | D#=Eb | E | F | F#=Gb | G | G#=Ab |
Hahaha
~~Table Markdown syntax get√~~
Okay
I didn't learn it after all
But... I learned that Markdown can paste HTML source code
So that's still something gained~For this problem, just replace the string according to the rules.
There is also the issue of letting the program process multiple times
The gets function is different from scanf
EOF should be !=NULL
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| #include<stdio.h>
int main() {
int kase=0;
char s[10];
while(gets(s)!=NULL) {
printf("Case %d: ",++kase);
if(s[1]==' ')
printf("UNIQUE\n");
else {
if(s[1]=='b') {
s[1]='#';
if(s[0]=='A')
s[0]='G';
else
s[0]--;
} else if(s[1]=='#') {
s[1]='b';
if(s[0]=='G')
s[0]='A';
else
s[0]++;
}
printf("%s\n",s);
}
}
return 0;
}
|
Reference solution
I don’t quite understand the C++
But that conversion is written more cleverly than mine
It seems necessary to review C++ knowledge again
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| #include<iostream>
#include<string>
using namespace std;
string trans(string a){
string b="";
if(a[1]=='#'){
b+=char((a[0]-'A'+1)%7+'A');
b+='b';
}else{
b+=char((a[0]-'A'+6)%7+'A');
b+='#';
}
return b;
}
int main(){
string a,b;
for(int t=1; cin>>a>>b; t++){
cout<<"Case "<<t<<": ";
if(a.length()==1)
cout<<"UNIQUE"<<endl;
else
cout<<trans(a)<<" "<<b<<endl;
}
return 0;
}
|
Problem address:【NYOJ】[1025]A Famous Music Composer