- 不是很难的一道题目
- #include
#include
using namespace std;
bool StrobogrammaticNumber(string str)
{
int n = str.size() - 1;
int i = 0;
while (i < n)
{
if (str[i] == str[n])
{
if (str[i] != ‘1’ && str[i] != 8 && str[i]!=‘0’)
{
return false;
}
}
else if (str[i] != str[n])
{
if (str[i] == ‘9’)
{
if (str[n] != ‘6’)
{
return false;
}
}
else if (str[i] == ‘6’)
{
if (str[n] != ‘9’)
{
return false;
}
}
else
{
return false;
}
}
i++;
n–;
}
if (str.size() % 2 == 1)
{
if (str[i] != ‘1’ && str[i] != 8 && str[i] != ‘0’)
{
return false;
}
}
return true;
}
int main()
{
cout << StrobogrammaticNumber(“96596”) << endl;
system(“pause”);
return 0;
}
[LeetCode] Strobogrammatic Number 对称数
最新推荐文章于 2021-03-22 13:40:57 发布