Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
错的不行了,求助!附代码#include <string.h> #include <iostream> using namespace std; int depth; char tmp[30]; char fn[60][30]; int nf, cnt; //ifstream cin ("fn.txt"); //ofstream cout ("cout.txt"); void sortFileName (char filename[][30], int size) { int i, j, k; for (i = 0; i < size - 1; i++){ char t[30]; strcpy (t, filename[i]); for (j = i + 1; j < size; j++) { if (strcmp (filename[j], filename[i]) < 0) { k = j; strcpy (filename[i], filename[j]); } } strcpy (filename[k], t); } } void printCont (int depth) { char filename[30][30]; int n = 0; int i, j, k; while (cnt < nf) { //a dir strcpy(tmp, fn[cnt++]); if (tmp[0] == '*' || tmp[0] == ']' ) break; if (tmp[0] == 'd') { for (j = 1; j <= depth + 1; j++) { cout << "|"; for (i = 1; i <= 5; i++){ cout << " "; } } cout << tmp << endl; printCont (depth + 1); }else { strcpy (filename[n++], tmp); } } sortFileName (filename, n); for ( i = 0; i < n; i++) { for (k = 0; k < depth; ++k) { cout << "|"; for (j = 1; j <= 5; j++) cout << " "; } cout << filename[i] << endl; } } int readData ( ) { nf = 0; while (1) { cin >> fn[nf]; if (fn[nf][0] == '*'){nf++; return 0;} if (fn[nf][0] == '#') return 1; nf++; } } int main ( ) { int ds = 0; while (1) { cnt = 0; int flag = readData ( ); if (flag == 1) break; cout << "DATA SET " << ++ds << ":" << endl; cout << "ROOT" << endl; printCont (0); cout << endl; } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator