- 帖子
- 4
- 主題
- 0
- 精華
- 0
- 積分
- 34
- 點名
- 0
- 作業系統
- Windows10
- 軟體版本
- office 2010
- 閱讀權限
- 10
- 性別
- 男
- 註冊時間
- 2020-2-15
- 最後登錄
- 2020-5-28
|
回復 1# andyto202
輸出所有集合:- #include <iostream>
- #include <string>
- #include <vector>
- #include <cstdlib>
- using namespace std;
- vector<int> ans;
- bool char_is_number(char c)
- {
- string number_string = "0123456789";
- if (number_string.find(c) != number_string.npos)
- {
- return true;
- }
- return false;
- }
- void get_three_number(string str)
- {
- int count_three = 0, index = 0, temp_number = 0;
- while (count_three < 3)
- {
- if (index == 0 && str[index] == ' ')
- {
- ans.push_back(ans[ans.size() - 3]);
- count_three++;
- }
- else
- {
- if (char_is_number(str[index]))
- {
- temp_number = temp_number * 10 + int(str[index]) - 48;
- }
- else
- {
- if (temp_number != 0)
- {
- ans.push_back(temp_number);
- temp_number = 0;
- count_three++;
- }
- }
- }
- index++;
- }
- }
- int main()
- {
- string inputString = "";
- int countThree = 0, i, j;
- while (getline(cin, inputString) && inputString != "q")
- {
- get_three_number(inputString);
- }
- // show ans
- for (i = 0; i < ans.size(); i += 3)
- {
- for (j = 1; j <= ans[i + 2]; j++)
- {
- cout << ans[i] << "/" << ans[i + 1] << "/" << j << endl;
- }
- cout << endl;
- }
- system("PAUSE");
- return 0;
- }
複製代碼 |
|