> For the complete documentation index, see [llms.txt](https://dfine.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://dfine.gitbook.io/leetcode/937.reorder_log_files.md).

# 937.Reorder Log Files

**937.Reorder Log Files**

难度:Easy

> 你有一个日志数组 logs。每条日志都是以空格分隔的字串。

对于每条日志，其第一个字为字母数字标识符。然后，要么：

标识符后面的每个字将仅由小写字母组成，或； 标识符后面的每个字将仅由数字组成。 我们将这两种日志分别称为字母日志和数字日志。保证每个日志在其标识符后面至少有一个字。

将日志重新排序，使得所有字母日志都排在数字日志之前。字母日志按内容字母顺序排序，忽略标识符；在内容相同时，按标识符排序。数字日志应该按原来的顺序排列。

返回日志的最终顺序。

示例 ：

```
输入：["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"]
输出：["g1 act car","a8 act zoo","ab1 off key dog","a1 9 2 3 1","zo4 4 7"]
```

提示：

0 <= logs.length <= 100 3 <= logs\[i].length <= 100 logs\[i] 保证有一个标识符，并且标识符后面有一个字。

先取出内容部分，然后将数字部分移到末尾，然后对于字母部分排序，冒泡排序即可。

```
class Solution {
public:
    vector<string> reorderLogFiles(vector<string>& logs) {
        vector<string>content;
        for(auto l : logs)
        {
            int i=0;
            while(l[i]!=' ')
                i++;
            string tmp=l.substr(i+1);
            content.push_back(tmp);
        }
       
        int second=logs.size()-1;
         int start=second-1;
        
        while(start>=0)
        {
            if(content[second][0] >='a' && content[second][0]<= 'z')         
            {
                if(content[start][0]>='0' && content[start][0] <= '9' )
                {
                    string t=content[start];
                    content[start]=content[second];
                    content[second]=t;
                     t=logs[start];
                    logs[start]=logs[second];
                    logs[second]=t;
                }
                else
                    start--;
                
            }
            else 
            {
                second--;
                if(second ==start)
                    start--;
            }
            
        }
        
        for(int i=0;i<content.size();i++)
            
        {
            if(content[i][0]>='0' && content[i][0]<='9' ) 
            {
                start=i;
                break;
            }
            }
        for(int i=0;i<start;i++)
            for(int j=i+1;j<start;j++)
            {
                if(content[i]>content[j])
                {
                    string t=content[i];
                content[i]=content[j];
                content[j] = t; 
                t=logs[i];
                logs[i]=logs[j];
                logs[j] = t; 
                }
                else if(content[i]==content[j])
                {
                    if(logs[i]>logs[j])
                    {
               string t=content[i];
                content[i]=content[j];
                content[j] = t; 
                t=logs[i];
                logs[i]=logs[j];
                logs[j] = t; 
                    }
                }
            }
        return logs;
    }
};
```

> 执行用时 : 20 ms, 在Reorder Log Files的C++提交中击败了96.79% 的用户\
> 内存消耗 : 16.3 MB, 在Reorder Log Files的C++提交中击败了7.50% 的用户


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://dfine.gitbook.io/leetcode/937.reorder_log_files.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
