20A - BerOS file system - CodeForces Solution


implementation *1700

Please click on ads to support us..

Python Code:

s = input()
_len, met = len(s), False

for i in range(_len - 1):
    if s[i] == '/' and s[i + 1] != '/':
        print('/', end='')
    elif s[i] != '/':
        print(s[i], end='')
        met = True

if not met or s[_len - 1] != '/':
    print(s[_len - 1], end='')

C++ Code:

#include <iostream>

int main(){

    std::string path; getline(std::cin, path);
    std::string output; bool flag(0);
    for(int k = 0; k < path.size(); k++){
        if(path[k] != '/' || flag == 0){output += path[k];}
        if(path[k] == '/'){flag = 1;}
        else{flag = 0;}
    }

    if(flag && output.size() > 1){output = output.substr(0, output.size() - 1);}
    std::cout << output << std::endl;

    return 0;
}


Comments

Submit
0 Comments
More Questions

1650C - Weight of the System of Nested Segments
1097A - Gennady and a Card Game
248A - Cupboards
1641A - Great Sequence
1537A - Arithmetic Array
1370A - Maximum GCD
149A - Business trip
34A - Reconnaissance 2
59A - Word
462B - Appleman and Card Game
1560C - Infinity Table
1605C - Dominant Character
1399A - Remove Smallest
208A - Dubstep
1581A - CQXYM Count Permutations
337A - Puzzles
495A - Digital Counter
796A - Buying A House
67A - Partial Teacher
116A - Tram
1472B - Fair Division
1281C - Cut and Paste
141A - Amusing Joke
112A - Petya and Strings
677A - Vanya and Fence
1621A - Stable Arrangement of Rooks
472A - Design Tutorial Learn from Math
1368A - C+=
450A - Jzzhu and Children
546A - Soldier and Bananas