日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

CDOJ_327 BerOS file system

發布時間:2025/5/22 编程问答 53 豆豆
生活随笔 收集整理的這篇文章主要介紹了 CDOJ_327 BerOS file system 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

原題地址:http://acm.uestc.edu.cn/#/problem/show/327




The new operating system BerOS has a nice feature. It is possible to use any number of characters?/?as a delimiter in path instead of one

?traditional?/. For example, strings?//usr///local//nginx/sbin//?and?/usr/local/nginx///sbin?are equivalent. The character?/?(or some?

sequence of such characters) at the end of the path is required only in case of the path to the root directory, which can be represented as?

single character?/.

A path called normalized if it contains the smallest possible number of characters?/.

Your task is to transform a given path to the normalized form.

Input

There are multi-cases. The first line of each case contains only lowercase Latin letters and character?/?— the path to some directory. All paths?

start with at least one character?/. The length of the given line is no more than?100?characters, it is not empty.

Output

The path in normalized form.

Sample input and output

Sample Input Sample Output
//usr///local//nginx/sbin /usr/local/nginx/sbin
題目大意是將路徑化為linux下的最簡格式,即目錄間由一個斜杠隔開,根目錄前有一個斜杠。說白了就是將多個斜杠變為一個。
此題可以使用常規思路,利用開關變量,不斷判斷是否為字母,然后整個單詞輸出。但是,巧妙利用C++的流處理,能非常簡單的處理這道題。 首先 ,需要聲明庫<sstream>,這是處理字符串流的庫。然后創建一個輸入流isstream is(s)(注意,這里的輸入并非指從鍵盤敲入,而是從字符串中 輸入),其中s是題中的字符串。接下來,就將is當作cin用,就可以啦。當然,需要處理一下剛開始的字符串,將所有/替換為空格。且需要注意的是 ,有一種特例是全為/,這種情況只需判斷一下是否輸出即可。 獻上代碼: #include<iostream> #include<string> #include<sstream> using namespace std;int main() {string s, temp;while (cin >> s){for (int i = 0; i < s.length(); i++)if (s[i] == '/')s.replace(i, 1, 1, ' ');//將斜杠代換為空格istringstream is(s);//創建輸入流bool flag = 0;//判斷是否有輸入while (is >> temp){cout << '/' << temp; flag = 1;}if (!flag)cout << '/';cout << endl;}return 0; }


轉載于:https://www.cnblogs.com/HarryGuo2012/p/4524051.html

總結

以上是生活随笔為你收集整理的CDOJ_327 BerOS file system的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。