In a classic file system, files can be included in folders or folders. In Unix-like operating systems, there is no drive letter, there is only one root directory/, and all other files or folders are its direct or indirect subdirectories (subfiles ).
File can be expressed as follows:
/<Directory>/.../<directory>/<File>
For example:/etc/APT/sources. List
The folder can be represented as follows:
/<Directory>/.../<directory>
For example:/var/WWW
Most users in Unix-like operating systems frequently use shell (command line interactive interface). Shell has a current directory. When users need to jump to another directory, they can use the CD command. For example, if the current directory is/home/Yuki, after executing CD.../../var/WWW, the current directory becomes/var/www. "..." Indicates the parent directory, and "..." indicates the parent directory of the parent directory. If the target directory is a subdirectory of the current directory, run CD to the target directory. For example, if the current directory is/, run CD VaR to directly enter the/var directory.
Similarly, now we can solve a simple problem by finding the path of the target file relative to the current file, which is similar to the parameter followed by the CD command (finding the relative path of the file can avoid folders .. and .. of course, in actual use, you can directly use/var/WWW (absolute path) to locate the file, but here you need to use relative path.
-
-
Input
-
-
There are multiple groups of input data. The first act is N, indicating that there are N groups of data. Then, each of the two actions is a group. The first action is the target path, and the second action is the current path. The total file name length is less than 255 and only contains lowercase letters A-Z.
Example 4/home/Yuki/data/file/home/user/pictures/root/file // a/B// b/a/B sample output .. /.. /Yuki/data/fileroot/rootfile .. /.. /.. /.. /B/a/B
This question is actually a simulation. You can take all the situations into account, that is, to compare two strings. First, let's see where the difference starts, then, you can check the number of '/' After the string in the current folder '.. 'operation, and then pay attention to the handling of various details... it may be difficult.
# Include <iostream> # include <string> using namespace STD; int main () {int t; CIN> T; string Mu, dang; For (INT I = 0; I <t; I ++) {CIN> mu; CIN> dang; string S = ""; int mu_len = Mu. length (); int dang_len = Dang. length (); Int J = 0; int p = 0; If (Dang = "/") cout <Mu. substr (1) <'\ n'; else {int da = 0; while (j <mu_len & J <dang_len) {If (MU [J] = dang [J]) {If (MU [J] = '/') {P ++; da = J ;} j ++;} else {break;} If (j = dang_len & Mu [J] = '/') {S = Mu. substr (J + 1);} else {J = da + 1; int K = J; int KK = J; int BO = 0; while (j <dang_len) {If (Dang [J] = '/') {S = S + ".. "; Bo = 1; break;} J ++; while (j <dang_len) {If (Dang [J] = '/') {S = S + "/.. ";} J ++;} If (BO = 1) S = S + "/.. "; else S = S + ".. "; if (k <mu_len) {While (k <mu_len) {If (MU [k] = '/') {S = S +"/"+ Mu. substr (KK, K-kk); KK = k + 1;} k ++;} s = S + "/" + Mu. substr (kk) ;}} cout <S <'\ n' ;}} return 0 ;}