2022-3-11
题目
代码
<iomanip>
<iostream>
<string>
int temp = 0;//暂存j值
int d = 0, m = 0, s = 0;//day, minute, second
string week[7] = { "MON","TUE", "WED", "THU", "FRI", "SAT", "SUN" };
string ss[4];
string str[4];
for (int i = 0; i < 4; i++)
{
getline(cin, ss[i]);
if (ss[i].length() < 60)
{
str[i] = ss[i].append(string((60 - ss[i].length()), '*'));
}
}
//for (int i = 0; i < 4; i++)
// cout << str[i];
//cout << str[0][6]; str类型可类比做指针用,具体不太明白
//d m
for (int i = 0; i < str[0].length(); i++)
{
if (!d)//d中没有数据时开始选择相同大写字母
{
if (((int)str[0][i] > 90) || ((int)str[0][i] < 65))//非大写字母跳过
continue;
for (int j = 0; (j < str[1].length()) && (j <= i); j++)
{
if (/*(*/str[0][i] == str[1][j]/*) && ((str[1][j] >= 65) && (str[1][j] <= 71))*/)//不知道第一个相同的会不会有陷阱出现其他字符
{
d = str[1][j] - 65;//存储为0~6,方便调用week数组
temp = j;
break;
}
}
}
else//d中有数据则开始选择相同字符‘0~9’、‘A~N’
{
//if ((((int)str[0][i] >= 48) && ((int)str[0][i] <= 57)) || (((int)str[0][i] >= 65) && ((int)str[0][i] <= 78)))
//{
// for (int j = 0; j < str[1].length(); j++)
// {
// if (str[0][i] == str[1][j])
// m = str[1][j];
// }
//}
//冗长的条件拆分成两组if比较方便阅读 (可能把...
if (((int)str[0][i] >= 48) && ((int)str[0][i] <= 57))
{
for (int j = temp; (j < str[1].length()) && (j <= i); j++)
{
if (str[0][i] == str[1][j])
{
m = str[1][j] - 48;//存储为0~9
break;
}
}
}
else if (((int)str[0][i] >= 65) && ((int)str[0][i] <= 78))
{
for (int j = temp; (j < str[1].length()) && (j <= i); j++)
{
if ((str[0][i] == str[1][j]) && (!m))
{
m = str[1][j] - 55;//储存为10~23
break;
}
}
}
if (m)//求到m后跳出
break;
}
}
//s
for (int i = 0; i < str[2].length(); i++)
{
if (s)//s得到后跳出
break;
if (((int)str[2][i] >= 65) && ((int)str[2][i] <= 90))
{
for (int j = 0; (j < str[3].length()) && (j <= i); j++)
{
if (str[2][i] == str[3][j])
{
s = i;//从0计数
break;
}
}
}
else if (((int)str[2][i] >= 97) && ((int)str[2][i] <= 122))
{
for (int j = 0; (j < str[3].length()) && (j <= i); j++)
{
if (str[2][i] == str[3][j])
{
s = i;
break;
}
}
}
}
//setw(x)设置x位宽度,setfill('0')以0填充
cout << week[d] << ' ' << setw(2) << setfill('0') << m << ':' << setw(2) << setfill('0') << s;
return;
想法
1.后两段检测到4
而不是s
才发现题目是上下同一位的字符,本以为是上面两个for
挨个检验。审题审题
2.有两个测试点错误,初步猜测是数组超限,但不会改,开摆。
3.希望这次能坚持每天做一个