閱讀103 返回首頁    go 阿裏雲 go 技術社區[雲棲]


1077: Slash

1077: Slash
Time Limit: 1 Sec Memory Limit: 128 MB
Submit: 3 Solved: 2
[Submit][Status][Web Board]
Description

The American English slash (/) is a punctuation mark. In the early modern period, in the Fraktur script, which was widespread through Europe in the Middle Ages, one slash(/) represented a comma, while two slashes (//) represented a dash.
With the wide use of computers, slash appeared far more than at any previous time in history. On Unix-like systems and in URLs, the slash is to separate directory and file components of a path:
/home/whuacm/chaeyeon/Sherlockpp.jpg
https://acm.whu.edu.cn/
But in Windows systems, it uses (\) to separate directory and file components of a path:
C:\Users\v-yungao\Music\Shake
That really confuses me. Could you help me to judge if the string I wrote is right.
Please notice that I would only make a mistake by changing (\) to (/) or (/) to (\). All the strings were constituted by a-z, A-Z, 0-9, (.) , (\) and (/), no other characters would appear in the strings.
A string of URL always begins with “[a-zA-Z]+://” (Notice (/) maybe changed to (\) ), in which “[a-zA-Z]+” represents any non-empty string of letters.
Windows path begins with “[a-zA-Z]:\” (Notice (\) maybe changed to (/)), in which “[a-zA-Z]” means an English letter. (e.g. “C:\\windows” is a URL not a Windows path)
The path of Unix-like system begins with (/) or (\).
I’ll give you some strings, can you tell me which type those strings belong to and those correct forms.
Input
The first line consists of an integer T, indicating the number of strings.
The next T lines, each line consists of a single non-empty string. All of those are really data from our daily life.
Output
For each string:
If it belongs to a path in Unix-like systems, output “It’s a path in Unix-like systems!” in a new line and the correct string in the next line.
If it belongs to a path in Windows system, output “It’s a path in Windows system!” in a new line and the correct string in the next line.
If it’s a URL, output “It’s a URL!” in a new line and the correct string in the next line.
The kind of each input string can be uniquely determined.

Constrains
0 < T <= 20
The length of each string will not be longer than 50.
Sample Input

4

https://acm.whu.edu.cn/felioj

http:/\acm.whu.edu.cn/11111011001

/\home\whuacm\Slash\yamaZ:\movie/chaeyeon

Sample Output

It's a URL!

https://acm.whu.edu.cn/felioj

It's a URL!https://acm.whu.edu.cn/11111011001/

It's a path in Unix-like systems!

/home/whuacm/Slash/yama

It's a path in Windows syste


請欲參加ACM大賽的同學練習問題集中的題目
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#include <iostream>
#include <string>
using namespace std;
 
int main()
{
    int testNum;
    string str;
    char ch;
 
    cin >> testNum;
    cin.get();
    for (int test = 1; test <= testNum; test++)
    {
        cin >> str;
        if (str[0] == '/' ||  str[0] == '\\')
        {//UINX
            for (int i = 0; i < str.size(); i++)
            {
                if (str[i] == '\\')
                    str[i] = '/';
            }
            cout << "It's a path in Unix-like systems!" << endl;
        }
        else
        {
            int i;
            for (i = 0; i < str.size(); i++)
            {
                if (str[i] == ':')
                    break;
            }
            //URL
            if (str[i+2] == '\\' || str[i+2] == '/')
            {
                cout << "It's a URL!" << endl;
                for (i = 0; i < str.size(); i++)
                {
                    if (str[i] == '\\')
                        str[i] = '/';
                }
            }//windows
            else
            {    for (i = 0; i < str.size(); i++)
                {
                    if (str[i] == '/')
                        str[i] = '\\';
                }
                cout << "It's a path in Windows system!" << endl;
            }
 
        }
 
        cout << str << endl;
    }
 
    return 0;
}
 
/**************************************************************
    Problem: 1077
    User: 1006440533
    Language: C++
    Result: Accepted
    Time:0 ms
    Memory:1272 kb
****************************************************************/





最後更新:2017-04-02 15:14:59

  上一篇:go 1060: NEW RDSP MODE I
  下一篇:go 水仙花數