Create your Gitee Account
Explore and code with more than 6 million developers,Free private repositories !:)
Sign up
This repository doesn't specify license. Without author's permission, this code is only for learning and cannot be used for other purposes.
Clone or download
ChuangGuanTest.cpp 931 Bytes
Copy Edit Web IDE Raw Blame History
fudum authored 2014-07-06 20:04 . 提交华为OJ程序
#include "stdafx.h"
#include "ChuangGuanTest.h"
ChuangGuanTest::ChuangGuanTest(void)
{
}
ChuangGuanTest::~ChuangGuanTest(void)
{
}
//英语单词玩游戏
int ChuangGuanTest::who(std::string in)
{
int ret = 0;
std::vector<PM> vec;
std::string strIn = in;
int len;
len = strIn.size();
//判断字符正确性
for (int i = 0; i < len; i++)
{
if (!(strIn[i] >='a' && strIn[i] <='z'))
{
return -1;
}
}
//权值弄到list中
for (int i = 0; i < len; i++)
{
PM pm;
pm.ch = strIn[i];
pm.quan = 0;
vec.push_back(pm);
}
//计算权值
for (int i = len - 1 ; i >= 0; i--)
{
if (i == len -1)
{
vec[i].quan = 0;
}
else
{
for (int j = i+1; j < len; j++)
{
if (vec[i].ch < vec[j].ch)
{
vec[i].quan = vec[j].quan +1;
break;
}
}
}
}
int max = 0;
for (int i = 0; i < len; i++)
{
if (vec[i].quan > max)
{
max = vec[i].quan;
}
}
ret = (len - max -1 ) % 2;
return ret;
}

Comment ( 0 )

Sign in for post a comment