Posted on 2008-06-08 00:45
superman 阅读(436)
评论(0) 编辑 收藏 引用 所属分类:
ZOJ
1 /* Accepted 1225 C++ 00:00.00 848K */
2 #include <cctype>
3 #include <iostream>
4
5 using namespace std;
6
7 bool cmp(const string & a, const string & b)
8 {
9 if(isdigit(a[0]) && isdigit(b[0]))
10 {
11 if(a.size() < b.size())
12 return true;
13 if(a.size() > b.size())
14 return false;
15 return a < b;
16 }
17 if(a[0] == '-' && b[0] == '-')
18 {
19 if(a.size() < b.size())
20 return false;
21 if(a.size() > b.size())
22 return true;
23 return a > b;
24 }
25 if(a[0] == '-' && isdigit(b[0]))
26 return true;
27 if(isdigit(a[0]) && b[0] == '-')
28 return false;
29
30 string ta, tb;
31 for(int i = 0; i < a.size(); i++)
32 ta += tolower(a[i]);
33 for(int i = 0; i < b.size(); i++)
34 tb += tolower(b[i]);
35
36 return ta < tb;
37 }
38
39 int main()
40 {
41 int n;
42 bool word[100];
43 string s[100];
44
45 while(true)
46 {
47 cin >> s[0];
48 if(s[0] == ".")
49 break;
50
51 if(isdigit(s[0][0]) || s[0][0] == '-')
52 word[0] = false;
53 else
54 word[0] = true;
55 s[0] = s[0].substr(0, s[0].size() - 1);
56
57 n = 1;
58 while(true)
59 {
60 if(getchar() == '\n')
61 break;
62
63 cin >> s[n];
64
65 if(isdigit(s[n][0]) || s[n][0] == '-')
66 word[n] = false;
67 else
68 word[n] = true;
69
70 s[n] = s[n].substr(0, s[n].size() - 1);
71
72 n++;
73 }
74
75 sort(s, s + n, cmp);
76
77 bool x[100] = { false };
78 for(int i = 0; i < n; i++)
79 {
80 if(word[i])
81 for(int j = 0; j < n; j++)
82 {
83 if(x[j] == false && isalpha(s[j][0]))
84 {
85 cout << s[j]; x[j] = true; break;
86 }
87 }
88 else
89 for(int j = 0; j < n; j++)
90 if(x[j] == false && (s[j][0] == '-' || isdigit(s[j][0])))
91 {
92 cout << s[j]; x[j] = true; break;
93 }
94 if(i == n - 1)
95 cout << '.' << endl;
96 else
97 cout << ',' << ' ';
98 }
99 }
100
101 return 0;
102 }
103