手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

[华为机试题]最大连续递增子串

[日期:2014-03-12] 来源:Linux社区  作者:hongkangwl [字体:大 中 小]

[华为机试题]最大连续递增子串

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int main()
{
    string s;
 string::size_type  length(0);
 cin>>s;
 string::size_type num = s.size();
 vector<char> ss, ss1;
 ss.clear();
 ss1.clear();


 for (string::size_type i = 0; i != num-1; i++)
 {
  if (s.at(i+1) > s.at(i))
  {
   if (i == num - 2)
   {
    cout<<s;
    return 0;
   }
  }
  else
   break;
 }
   
 /*for (string::size_type i = 0; i != num - 1; i++)
    {
      if (s.at(0) == s.at(i))
      {
    if (i == num -2)
    {
    cout<<(s.at(0));
    return 0;
    }
      }
  else
    break;
    }*/


 for (string::size_type i = 0; i != num-1; i++)
    { 
       
  if (s.at(i+1) > s.at(i))
  {
   if (ss.empty())
   {
    ss.push_back(s.at(i));
   }
            ss.push_back(s.at(i+1));
   
       
  }
  else
  {
          if (ss.size() > length)
          {
      length = ss.size();
      ss1 = ss;
          }
    else if (ss.size() == length)
    {
      if (ss > ss1)
      {
      ss1 = ss;
      }
    }
      ss.clear();
         

  }
          if (i == num -2)
          {
    if (ss.size() > length)
    {
      length = ss.size();
      ss1 = ss;
    }
    else if (ss.size() == length)
    {
      if (ss > ss1)
      {
      ss1 = ss;
      }
    }
          }

 
 
    }
 for (vector<char>::iterator iter =ss1.begin() ; iter != ss1.end(); iter++)
 {
  cout<<(*iter);
 }
   
 return 0;
}

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款