测试字符串是否相等

来源:互联网 发布:matlab遗传算法的原理 编辑:程序博客网 时间:2024/05/07 08:32

第一种方法,使用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();
}




0 0
原创粉丝点击