精华内容
下载资源
问答
  • Unix语言 模拟unix ls命令的AC程序。
  • 例题5-8 Unixls命令(Unix ls,UVa400) 输入正整数n以及n个文件名,按照字典序排序后按列优先的方式左对齐输出。 假设最长文件名有M字符,则最右列有M字符,其他列都是M+2字符。 Sample Input 10 tiny 2short4me ...

    例题5-8 Unixls命令(Unix ls,UVa400) 输入正整数n以及n个文件名,按照字典序排序后按列优先的方式左对齐输出。 假设最长文件名有M字符,则最右列有M字符,其他列都是M+2字符。
    Sample Input
    10
    tiny
    2short4me
    very_long_file_name
    shorter
    size-1
    size2
    size3
    much_longer_name
    12345678.123
    mid_size_name
    12
    Weaser
    Alfalfa
    Stimey
    Buckwheat
    Porky
    Joe
    Darla
    Cotton
    Butch
    Froggy
    Mrs_Crabapple
    P.D.
    19
    Mr._French
    Jody
    Buffy
    Sissy
    Keith
    Danny
    Lori
    Chris
    Shirley
    Marsha
    Jan
    Cindy
    Carol
    Mike
    Greg
    Peter
    Bobby
    Alice
    Ruben

    Sample Output

    ------------------------------------------------------------
    12345678.123         size-1             
    2short4me            size2              
    mid_size_name        size3              
    much_longer_name     tiny               
    shorter              very_long_file_name
    ------------------------------------------------------------
    Alfalfa        Cotton         Joe            Porky        
    Buckwheat      Darla          Mrs_Crabapple  Stimey       
    Butch          Froggy         P.D.           Weaser       
    ------------------------------------------------------------
    Alice       Chris       Jan         Marsha      Ruben     
    Bobby       Cindy       Jody        Mike        Shirley   
    Buffy       Danny       Keith       Mr._French  Sissy     
    Carol       Greg        Lori        Peter     
    

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=341

    [注意] 一行最后一个单词后面不要有两个空格
    [注意] 每组最后一个单词后面不用空2格
    算行数时向上取整
    输出时,设置额外的break条件,即已经输出完最后一个,不要继续越界输出

    其余看代码

    #include<iostream>
    #include<vector>
    #include<string>
    #include<algorithm>
    #include<cmath>
    using namespace std;
    
    /*
    [注意] 一行最后一个单词后面不要有两个空格
    [注意] 每组最后一个单词后面不用空2格
    算行数时向上取整
    输出时,设置额外的break条件,即已经输出完最后一个,不要继续越界输出
    
    */
    
    int main()
    {
        int N;
        while(cin>>N){
            vector<string> list;
            int max_len = 0;
            for(int i=0;i<N;i++){
                string str;
                cin>>str;
                max_len = max_len < str.size() ? str.size() : max_len;
                list.push_back(str);
            }
    
    
    
            sort(list.begin(), list.end());
            int count_col = 0;  // 列数
            int count_line = 0; //行数
            count_col = (60+2) / (max_len+2);
            count_line = ceil((double)list.size() / count_col); //[注意]这里除的时候要转换为浮点型
            // cout<<list.size()<<" "<<(double)list.size() / count_col + 0.5<<endl;
            // cout<<max_len<<" "<<count_col<<" "<<count_line<<endl;
    
            for(int i=0;i<60;i++)
                cout<<"-";  
            cout<<endl;
            for(int i=0;i<count_line;i++){     // 第几行
                for(int k=0; k<count_col && (i+k*count_line)<list.size(); k++){  // 第几列, 循环判断条件中,加上判输出单词个数足够
                    if(k>0)  //作为两个词块之间间隔的空格,每行第一个之前没有
                        cout<<"  ";
    
                    string out = list[i+k*count_line];
                    cout<<out;
    
                    //输出每个单词后面的占位空格 (不算单词块之间2个空格的间隔)
                    for(int j=0;j<max_len-out.size();j++) 
                        cout<<" ";
                }
                cout<<endl;
            }
    
        }
        return 0;
    }
    
    // AC at 2019/2/2 00:22
    

    没什么难度,注意注意点就行, 感谢 udebug
    https://www.udebug.com/UVa/400

    展开全文
  • Unix ls

    2015-08-01 09:47:26
    Unix ls Description The computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your a

    Unix ls

    Description

    The computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your assignment is to write the formatter for the ls function.

    Your program will eventually read input from a pipe (although for now your program will read from the input). Input to your program will consist of a list of (F) filenames that you will sort (ascending based on the ASCII character values) and format into (C) columns based on the length (L) of the longest filename. Filenames will be between 1 and 60 (inclusive) characters in length and will be formatted into left-justified columns. The rightmost column will be the width of the longest filename and all other columns will be the width of the longest filename plus 2. There will be as many columns as will fit in 60 characters. Your program should use as few rows (R) as possible with rows being filled to capacity from left to right.


    Input

    The input will contain an indefinite number of lists of filenames. Each list will begin with a line containing a single integer (1 <= N <= 100). There will then be N lines each containing one left-justified filename and the entire line's contents (between 1 and 60 characters) are considered to be part of the filename. Allowable characters are alphanumeric (a to z, A to Z, and 0 to 9) and from the following set { ._- } (not including the curly braces). There will be no illegal characters in any of the filenames and no line will be completely empty.

    Immediately following the last filename will be the N for the next set or the end of file. You should read and format all sets in the input.


    Output

    For each set of filenames you should print a line of exactly 60 dashes (-) followed by the formatted columns of filenames. The sorted filenames 1 to R will be listed down column 1; filenames R+1 to 2R listed down column 2; etc.


    Sample Input

    10
    tiny
    2short4me
    very_long_file_name
    shorter
    size-1
    size2
    size3
    much_longer_name
    12345678.123
    mid_size_name
    12
    Weaser
    Alfalfa
    Stimey
    Buckwheat
    Porky
    Joe
    Darla
    Cotton
    Butch
    Froggy
    Mrs_Crabapple
    P.D.
    19
    Mr._French
    Jody
    Buffy
    Sissy
    Keith
    Danny
    Lori
    Chris
    Shirley
    Marsha
    Jan
    Cindy
    Carol
    Mike
    Greg
    Peter
    Bobby
    Alice
    Ruben


    Sample Output

    ------------------------------------------------------------
    12345678.123         size-1
    2short4me            size2
    mid_size_name        size3
    much_longer_name     tiny
    shorter              very_long_file_name
    ------------------------------------------------------------
    Alfalfa        Cotton         Joe            Porky
    Buckwheat      Darla          Mrs_Crabapple  Stimey
    Butch          Froggy         P.D.           Weaser
    ------------------------------------------------------------
    Alice       Chris       Jan         Marsha      Ruben
    Bobby       Cindy       Jody        Mike        Shirley
    Buffy       Danny       Keith       Mr._French  Sissy
    Carol       Greg        Lori        Peter
    

    大意:

    给出一个数字N,接下来N行给出N个文件名,按照ASCII码顺序,将N个文件名输出;

    输出时将输出数据分为行和列,每一个测试集除最后一列外,前面的所有列宽度为最大文件名长度+2;

    同是除最后一列外,若文件名长度 < 最大文件名长度+2,则补上空格;

    要点:

    若是列和行计算错误可能会导致浮点误差;

    列的计算方式为l = (60 - max) / (max + 2) + 1;

    行的计算方式为r = num / l,如果num % l != 0,r++;

    注意最后一行的最后一列如上面测试3的Peter,Peter之后应该是不在输出空格的,直接输出结束;

    代码:

    #include <stdio.h>
    #include <string.h>
    #include <algorithm>
    using namespace std;
    
    int cmp(const void *a, const void *b){
    	return strcmp((char *)a, (char *)b);
    }
    
    int main(){
    	int num;
    	char str[105][65];
    	while (scanf("%d", &num) != EOF){
    		getchar();
    		int count = 0;
    		int max = 0;
    		int n = num;
    		while (n--){
    			scanf("%s", str[count++]);
    			if (max < strlen(str[count - 1]))
    				max = strlen(str[count - 1]);
    		}
    		qsort(str, count,sizeof(str[0]), cmp);
    		for (int i = 0; i < 60; i++)
    			printf("-");
    		printf("\n");
    		int l = (60 - max) / (max + 2) + 1;
    		int r = num / l;
    		if (num % l != 0)
    			r++;
    		for (int i = 0; i < r; i++){
    			for (int j = 0, p = i; j < l; j++){
    				printf("%s", str[p]);
    				p += r;
    				if (p >= num)
    					break;
    				for (int k = 0; k < max + 2 - strlen(str[p - r]); k++)
    					printf(" ");
    				
    			}
    			printf("\n");
    		}
    	}
    
    }





    
    展开全文
  • unix ls

    2015-04-22 22:35:15
    // // my_ls.c // myShell // // Created by baodong on 4/22/15. // Copyright (c) 2015 baodong. All rights reserved. //#include #include #include "apue.h" #include "myErr.h"int
    //
    //  my_ls.c
    //  myShell
    //
    //  Created by baodong on 4/22/15.
    //  Copyright (c) 2015 baodong. All rights reserved.
    //
    
    #include <dirent.h>
    #include <sys/stat.h>
    #include "apue.h"
    #include "myErr.h"
    
    int main(int argc, const char * argv[]) {
        DIR *dp;
        struct dirent *dirp;
        struct stat st;
    
        if (argc != 2) {
            err_quit("usage:ls 文件夹名");
        }
    
        if ((dp = opendir(argv[1])) == NULL) {
            err_quit("不能打开%s",argv[1]);
        }
        while ((dirp = readdir(dp)) != NULL) {
            stat(dirp->d_name, &st);
            printf("%s\t\t%.2f\tKb\n",dirp->d_name,st.st_size/1000.0);
        }
        closedir(dp);
    
        return 0;
    }
    
    展开全文
  • unix ls命令The ls command is one of the most commonly used commands in daily Linux/UNIX operations. The command is used in listing contents inside a directory and is one of the few commands beginners ...

    unix ls命令

    The ls command is one of the most commonly used commands in daily Linux/UNIX operations. The command is used in listing contents inside a directory and is one of the few commands beginners learn from the onset. In this guide, we will discuss Common ls commands in Linux and other parameters as well that may be used alongside the command.

    ls命令是日常Linux / UNIX操作中最常用的命令之一。 该命令用于列出目录内的内容,是初学者从一开始就学习的少数命令之一。 在本指南中,我们将讨论Linux中的Common ls命令以及可与该命令一起使用的其他参数。

    使用ls命令列出文件,不带任何参数 (Listing Files with ls command without any arguments)

    The ls command without any options lists files and directories in a plain format without displaying much information like file types, permissions, modified date and time to mention just but a few.
    Syntax

    不带任何选项的ls命令以纯格式列出文件和目录,而不显示很多信息,例如文件类型,权限,修改的日期和时间(仅提及其中一些)。
    句法

    $ ls

    以相反的顺序列出文件 (Listing files in reverse order)

    To list files in reverse order, append the -r flag as shown

    要以相反顺序列出文件,请附加-r标志,如下所示

    Syntax

    句法

    $ ls -r

    As you can see above, the order of the listing has changed from the last to the first in comparison to the previous image.

    如上所示,与上一张图片相比,清单的顺序从最后一个更改为第一个。

    使用-l选项列出文件和目录权限 (Listing file and directory permissions with -l option)

    using the -l flag, you can list the permissions of the files and directories as well as other attributes such as folder names, file and directory sizes, and modified date and time.

    使用-l标志,可以列出文件和目录的权限以及其他属性,例如文件夹名称,文件和目录大小以及修改的日期和时间。

    Syntax

    句法

    $ ls -l

    以易于阅读的格式查看文件 (Viewing files in a human-readable format)

    As you may have noticed, the file and folder sizes displayed are not easy to decipher and make sense of at first glance. To easily identify the file sizes as kilobytes (kB), Megabytes (MB) or Gigabytes (GB), append the -lh flag as shown

    您可能已经注意到,显示的文件和文件夹大小不容易解读,乍一看也很有意义。 要轻松地将文件大小标识为千字节(kB),兆字节(MB)或千兆字节(GB),请附加-lh标志,如下所示

    Syntax

    句法

    $ ls -lh

    查看隐藏文件 (Viewing Hidden files)

    You can view hidden files by appending the -a flag. Hidden files are usually system files that begin with a full stop or a period.

    您可以通过附加-a标志来查看隐藏的文件。 隐藏文件通常是以句号或句点开头的系统文件。

    Syntax

    句法

    $ ls -a

    递归列出文件 (Listing files recursively )

    To display the directory tree of files and folders use the ls -R command as shown

    要显示文件和文件夹的目录树,请使用ls -R命令,如下所示

    Syntax

    句法

    $ ls -R

    列出文件和目录的末尾带有'/'字符 (Listing files and directories with the ‘/’ character at the end)

    If you wish to go ahead and further distinguish files from folders, use the -F flag such that folder will appear with a forward slash character ‘/’ at the end.

    如果希望继续进行操作,并进一步将文件与文件夹区分开,请使用-F标志,以使该文件夹的末尾带有正斜杠字符“ /”。

    Syntax

    句法

    $ ls -F

    显示文件和目录的索引节点数量 (Displaying the inode number of files and directories)

    To display the inode number of files and directories, append the -i flag at the end of the ls command as shown

    要显示文件和目录的索引节点数量,请在ls命令末尾附加-i标志,如下所示

    Syntax

    句法

    $ ls -i

    显示文件和目录的UID和GID (Displaying the UID & GID of files and directories)

    If you want to display the UID as well as the GId of files and directories, append the -n parameter as shown

    如果要显示文件和目录的UID以及GID,请附加-n参数,如下所示

    Syntax

    句法

    $ ls -n

    在别名中定义ls命令 (Defining ls command in aliases)

    Aliases are customized or modified commands in Linux shell which are used in the place of the original commands. We can create an alias for the ls command this way

    别名是Linux外壳程序中的自定义或修改的命令,用于代替原始命令。 我们可以这样创建ls命令的别名

    Syntax

    句法

    $ alias="ls -l"

    What this does is that it tells the system to execute the ls -l command instead of the ls command. Be sure to observe that the output you get when running the ls command thereafter, will be as though you run the ls -l command.

    这是因为它告诉系统执行ls -l命令而不是ls命令。 请确保观察到,此后运行ls命令时获得的输出就像运行ls -l命令一样。

    To remove the added alias, run

    要删除添加的别名,请运行

    unalias ls

    着色ls命令输出 (colorizing ls command output)

    To add some flair to the output display based on the types of files, you may want to colorize your output to easily distinguish files, folders and other attributes such as file and directory permissions. To achieve this run

    要基于文件类型在输出显示中添加一些特色,您可能希望对输出进行着色,以轻松地区分文件,文件夹和其他属性,例如文件和目录权限。 要实现此运行

    Syntax

    句法

    ls --color

    显示ls命令版本 (Displaying the ls command version)

    If you are a bit curious as to what version of ls you are running, execute the command below

    如果您对正在运行的ls版本有点好奇,请执行以下命令

    # ls --v
    ls (GNU coreutils) 8.22
    Copyright (C) 2013 Free Software Foundation, Inc.
    License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
    This is free software: you are free to change and redistribute it.
    There is NO WARRANTY, to the extent permitted by law.
    
    Written by Richard M. Stallman and David MacKenzie.
    #

    You can also execute the command ls --version to print the ls command version.

    您也可以执行命令ls --version打印ls命令版本。

    显示ls命令帮助页面 (Displaying the ls command help page)

    To view more options and what you can do with ls simply run]

    要查看更多选项以及使用ls可以做什么,只需运行]

    ls --help

    访问ls手册页 (Accessing ls man pages)

    Alternatively, you can view the manpages to find out more about its usage by running

    或者,您可以通过运行以下命令查看手册页,以了解有关其用法的更多信息

    man ls

    That’s all we had for you today. We hope at this point, you will be more comfortable using the ls command in your day to day operations. Feel free to weigh in your feedback. Thanks!

    那就是我们今天为您准备的一切。 我们希望在这一点上,您将在日常操作中使用ls命令更加自在。 随时权衡您的反馈意见。 谢谢!

    翻译自: https://www.journaldev.com/24210/ls-command-in-linux-unix

    unix ls命令

    展开全文
  • 题目链接 输入正整数n以及n个文件名,排序后按列优先的方式左对齐输出。假设最长文件名 有M字符,则最右列有M字符,其他列都是M+2字符。 样例输入(略,可以由样例输出推出) 样例输出: ...首先计算出M并算出行数...
  • POJ 1589 Unix ls

    2015-04-03 19:02:18
    POJ 1589 Unix ls
  • 400 - Unix ls

    2013-07-17 21:00:10
    400 - Unix ls  Unix ls  The computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced
  • unix ls命令实现

    2012-05-08 22:58:20
    c实现unix ls -l命令,里边注释不是很多,但是每个函数都不难
  • unix ls 命令

    千次阅读 2015-08-18 21:02:08
    ls 命令选项详解  ls 命令可以说是Linux下最常用的命令之一。它有众多的选项,其中有很多是很有用的,你是否熟悉呢?下面列出了 ls 命令的绝大多数选项。  -a 列出目录下的所有文件,包括以 . 开头的隐含文件。...
  • The computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your assignment is to w...
  • UVA 400 Unix ls

    2017-05-21 19:40:15
    Unix ls  The computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your ...
  • unix ls命令

    2015-02-05 20:25:00
    [语法]: ls [-RadCxmlnogrtucpFbqisf1] [文件夹或文件......] [说明]: ls 命令列出指定文件夹下的文件,缺省文件夹为当前文件夹 ./,缺省输出顺序为纵向按字符顺序排列。 -R递归地列出每一个子文件夹的内容 ...
  • 400:Unix ls

    2019-10-07 06:38:13
    Unix ls#include<iostream> #include<vector> #include<algorithm> using namespace std; const int len = 60 + 2; void print(const string& s,int len,char extra){...
  • Unix ls, UVa 400

    2017-09-01 00:08:25
    Unix ls, UVa 400题解
  • 原题链接:https://vjudge.net/problem/UVA-400 分类:<string> 备注:排序和字符串处理 代码如下: #include<iostream> #include<string> #include<vector> ...int ma...
  • UVA400 Unix ls

    2017-10-20 16:17:42
    字典序,直接套用的Collections.sort()进行快速排序 import java.util.ArrayList; import java.util.Collections; import java.util.Scanner;/** * Created by 95112 on 10/...public class Unix_ls { public static
  • 输入正整数N以及N个文件名,排序后按列优先的方式左对齐输出。假设最长文件名有M个字符,则最右列有M个字符,其他列都是M+2个字符,不够的则在末尾补空格字符。要求输出的每行的总字符数不超过60,且行数最小 ...
  • UVA400 Unix Is命令 Unix ls

    2021-04-10 16:22:27
    题目描述 输入正整数n 以及n个文件名,排序后按列优先的方式左对齐输出。假设最长文件名有M 字符,则最右边有M 字符,其他列都是M+2 字符。 输入样例 10 tiny 2short4me very_long_file_name shorter ...
  • Uva 400 Unix ls

    2014-07-23 17:02:29
    Unix ls Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu SubmitStatusPracticeZOJ 1324 Description The computer company you work for is introducing a brand new compu
  • F - Unix ls

    2018-07-28 09:56:00
    The computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your assignment is to w...
  • Unix ls UVA - 400

    2021-01-31 16:13:08
      The computer company you work for is introducing a brand new computer line and is developing a new Unix-like operating system to be introduced along with the new computer. Your assignment is to ...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 4,123
精华内容 1,649
关键字:

lsunix