Uva - 400 - Unix ls】的更多相关文章

csdn : https://blog.csdn.net/su_cicada/article/details/86773007 例题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_lon…
题目其实很简单,答题意思就是从管道读取一组文件名,并且按照字典序排列,但是输入的时候按列先输出,再输出行.而且每一行最多60个字符.而每个文件名所占的宽度为最大文件名的长度加2,除了输出在最右边的文件名的宽度是最大文件名长度之外.编程实现这个功能,这就是Unix系统下ls命令的一部分而已.具体实现如下.主要学习的技能要点就是如何用偏移位移法来按列输出.如果一个矩阵n行m列,要按照列输出.但是我们知道,编程时候,只能是for(行)在列.所以必须要有一个偏移量来计算这种偏移关系.x = rows *…
先计算出最长文件的长度M,然后计算列数和行数,最后输出即可. AC代码: #include <iostream> #include <cstdio> #include <cstdlib> #include <cctype> #include <cstring> #include <string> #include <sstream> #include <vector> #include <set>…
这题的需要注意的地方就是计算行数与列数,以及输出的控制. 题目要求每一列都要有能够容纳最长文件名的空间,两列之间要留两个空格,每一行不能超过60. 简单计算下即可. 输出时我用循环输出空格来解决对齐的,其实可以用一个很巧妙的方法,用printf("%-*s", k, file[i]),查过资料后发现*放到转换字符之间可以当作替代符,后面可以输入一个变量(如k)来控制,这句代码意思是输出左对齐(对应负号)的宽度为k(对应*)的字符串file[i]. 代码: #include <cs…
题意:给出n个字符串,按照字典序排列,再按照规则输出. ===学习的紫书,题目意思很清楚,求列数和行数最开始看的时候木有看懂啊啊啊 列数:即为(60-M)/(M+2)+1;即为先将最后那一列减去,算普通的有多少列,算完了再加上最后一列 行数:可以用紫书里面的(n-1)/cols+1,也可用ceil函数 再将坐标对应成第几个字符串算出来,是像这个图的箭头标示的从上到下- #include<iostream> #include<cstdio> #include<cstring&g…
给你一堆文件名,排序后按列优先的方式左对齐输出. 假设最长文件名长度是M,那么每一列都要有M+2字符,最后一列有M字符. inmanip真NB..orz #include <iostream> #include <cstdio> #include <cstdlib> #include <vector> #include <string> #include <cstring> #include <iomanip> #incl…
简单题 #include <bits/stdc++.h> using namespace std; const int maxn=110; string s[maxn]; int main() { // freopen("data.in","r",stdin); ios::sync_with_stdio(false); int N; while (cin>>N) { int maxlen=-1; for (int i=0;i<N;i++…
题目链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=341 14438645 400 Unix ls Accepted C++ 0.048 2014-10-28 16:11:17 14438408 400 Unix ls Wrong answer C++ 0.048 2014-10-28 15:41:50 14438381 400 Un…
 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 assignment is to write the formatter for the ls function. Your…
  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 progra…