8.8 网易笔试 最小字符串 C++
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
bool check(string s) {
int cSize = s.size();
string strTmp(cSize, '\0');
int tm = 0;
for (int i=cSize-1;i>=0;i--)
{
strTmp[tm++]=s[i];
}
for (int i=0;i<cSize;i++)
{
if (s[i]!=strTmp[i])
{
return false;
}
}
return true;
}
int main() {
string str;
cin >> str;
int n = str.size();
string tmp = str;
for (int i=0;i<n;i++)
{
if(check(tmp)==false)
{
tmp = str.insert(n, 1, str[i]);
}
}
cout << tmp << endl;
return 0;
}
#网易##笔试题目#
#include<cstring>
#include<string>
using namespace std;
bool check(string s) {
int cSize = s.size();
string strTmp(cSize, '\0');
int tm = 0;
for (int i=cSize-1;i>=0;i--)
{
strTmp[tm++]=s[i];
}
for (int i=0;i<cSize;i++)
{
if (s[i]!=strTmp[i])
{
return false;
}
}
return true;
}
int main() {
string str;
cin >> str;
int n = str.size();
string tmp = str;
for (int i=0;i<n;i++)
{
if(check(tmp)==false)
{
tmp = str.insert(n, 1, str[i]);
}
}
cout << tmp << endl;
return 0;
}
#网易##笔试题目#