第一种方法,使用QT实现
#include <QCoreApplication>
#include <qtextstream.h>
#include <qstring.h>
#include <qdebug.h>
bool checkChar(QString str)
{
if(str.size() >1)
{
QChar tmp[1] = str[0];
int i = 1;
while (i < str.size())
{
if(tmp[0] == str[i])
{
tmp[0] = str[i];
++i;
}
else
{
return false;
}
}
return true;
}
else
{
return false;
}
}
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QString str;
QTextStream stream(stdin);
while (1) {
str.clear();
stream>>str;
qDebug("%d", checkChar(str));
}
return a.exec();
}