A chord
先用一个字符串数组存储音符表,注意 每次输入都需要排序,在通过枚举得到音符的数字编号和后续处理。
代码如下:
#include <cstdio>
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
string y[13] = {"C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "B", "H"};
string c1, c2, c3;
int place[4];
int flag;
cin >> c1 >> c2 >> c3;
for (int i = 0; i < 12; i++)
{
if (c1 == y[i])
place[1] = i;
if (c2 == y[i])
place[2] = i;
if (c3 == y[i])
place[3] = i;
}
for (int k = 1; k <= 3; k++)
{
for (int i = 1; i <= 3; i++)
{
for (int j = 1; j < i; j++)
{
if (place[j] > place[i])
swap(place[i], place[j]);
}
}
if ((abs(place[1] - place[2]) == 4 && abs(place[2] - place[3]) == 3))
flag = 1;
else if ((abs(place[1] - place[2]) == 3 && abs(place[2] - place[3]) == 4))
flag = 2;
place[1] += 12;
}
if (flag == 1)
cout << "major";
else if (flag == 2)
cout << "minor";
else
cout << "strange";
}
B:keybrd
对于输入的小写字母现在键盘内找到,每找到一次再寻找一次键盘寻找shift,计算距离,从而找出最优方案。
代码如下:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int n,m,len,vis[27],ans;
double dis[27],x;
char map[35][35];
double diss(int x,int y,int xx,int yy){return sqrt((x-xx)*(x-xx)+(y-yy)*(y-yy));}
string a;
int main()
{
ios::sync_with_stdio(false);
cin>>n>>m>>x;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>map[i][j];
if(map[i][j]>='a')vis[map[i][j]-'a'+1]=1;
}
}
for(char g='a';g<='z';g++)
{
dis[g-'a'+1]=55;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(map[i][j]==g)
for(int k=1;k<=n;k++)
for(int h=1;h<=m;h++)
if(map[k][h]=='S')dis[g-'a'+1]=min(dis[g-'a'+1],diss(i,j,k,h));
}
cin>>len>>a;
for(int i=0;i<len;i++)
{
if((a[i]<='Z'&&dis[a[i]-'A'+1]==55)||(a[i]>='a'&&!vis[a[i]-'a'+1]))
{
cout<<-1;
return 0;
}
if(a[i]<='Z'&&dis[a[i]-'A'+1]>x)ans++;
}
cout<<ans;
return 0;
}
C trains
直接模拟,注意数据要开long long
代码如下:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
ll a,b,c,n,m;
scanf("%lld%lld",&a,&b);
c=__gcd(a,b);
ll res=a*b/c;
res--;
n=res/a;
m=res/b;
if(n>m)m++;
else if(n<m)n++;
else
{
printf("Equal ");
return 0;
}
if(n>m)puts("Dasha");
else if(n==m)printf("Equal ");
else printf("Masha ");
return 0;
}