命令行选项

命令行选项
stringstream 

getline記得特殊處理一下數字n到第一行字符串中間的換行

 1 #include <iostream>
 2 #include <string>
 3 #include <cstring>
 4 #include <algorithm>
 5 #include <vector>
 6 #include <sstream>
 7 using namespace std;
 8 int A[27];
 9 bool C[27];
10 string B[27];
11 int main()
12 {
13     string s;
14     ios::sync_with_stdio(false);
15     cin >> s;
16     int len = s.length();
17     memset(A, 0, sizeof A);
18     for (int i = 0; i < len; i++)
19     {
20         if (i + 1 < len && s[i + 1] == ':')
21         {
22             A[s[i] - 'a'] = 1;
23             i++;
24         }
25         else
26         {
27             A[s[i] - 'a'] = 2;
28         }
29     }
30     int n;
31     cin >> n;
32     getline(cin, s);
33     for (int i = 0; i < n; i++)
34     {
35         //getline(cin,s);
36         memset(C, 0, sizeof C);
37         getline(cin, s);
38         cout << "Case " << i + 1 << ": ";
39         stringstream a;
40         a << s;
41         a >> s;
42         while (a >> s)
43         {
44 
45             if (s.length() == 2 && s[0] == '-' && s[1] >= 'a' && s[1] <= 'z')
46             {
47                 if (A[s[1] - 'a'] == 1)
48                 {
49                     a >> B[s[1] - 'a'];
50                 }
51                 else if (!A[s[1] - 'a'])
52                     break;
53                 C[s[1] - 'a'] = 1;
54             }
55             else
56                 break;
57         }
58         for (int i = 0; i < 26; i++)
59         {
60             if (C[i])
61             {
62                 cout << '-' << char(i + 'a') << ' ';
63             }
64             if (C[i] && A[i])
65             {
66                 cout << B[i] << ' ';
67             }
68         }
69         cout << '\n';
70     }
71 }

 

posted @ 2019-11-22 22:24  liulex  阅读(436)  评论(0编辑  收藏  举报