zoukankan      html  css  js  c++  java
  • HD-ACM算法专攻系列(8)——排序

    题目描述:

    源码:

    #include"iostream"
    #include"string"
    using namespace std;
    
    void Order(int *p, int n)
    {
    	int tmp;
    	if(n < 2)return;
    	for(int i = 0; i < n - 1; i++)
    	{
    		for(int j = 0; j < n - i - 1; j++)
    		{
    			if(p[j] > p[j + 1])
    			{
    			    tmp = p[j];
    				p[j] = p[j + 1];
    				p[j + 1] = tmp;
    			}
    		}
    	}
    }
    
    
    int main()
    {
    	string str;
    	int nums[501], count, start, len, num;
    	bool ok;
    	while(cin>>str)
    	{
    		count = 0;
    		start = 0;
    		len = str.length();
    		for(int i = 0; i < len; i++)
    		{
    			if(str[i] == '5')
    			{
    				start++;
    			}
    			else
    			{
    				break;
    			}
    		}
    		num = 0;
    		ok = true;
    		for(int i = start; i < len; i++)
    		{
    			if(str[i] != '5')
    			{
    				ok = true;
    				num = num * 10 + (str[i] - '0');
    			}
    			else
    			{
    				if(ok)
    				{
    					nums[count] = num;
    					count++;
    					num = 0;
    					ok = false;
    				}
    			}
    		}
    		if(str[len - 1] != '5')
    		{
    			nums[count] = num;
    			count++;
    		}
    		
    		Order(nums, count);
    		for(int i = 0; i < count; i++)
    		{
    			if(i > 0)cout<<" ";
    			cout<<nums[i];
    		}
    		cout<<endl;
    	}
        return 0;
    }
    

      

  • 相关阅读:
    百度地图API示例之小实践 添加代理商标注
    MySQL分组操作
    MySQL连表操作
    MySQL多对多操作
    MySQL一对一操作
    MySQL唯一索引
    MySQL用户授权管理
    MySQL外键操作
    MySQL删操作
    MySQL增操作
  • 原文地址:https://www.cnblogs.com/forcheng/p/7634864.html
Copyright © 2011-2022 走看看