Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cctype>
- #include <iostream>
- using namespace std;
- int main(int argc, char const* argv[])
- {
- char* buffer = new char[128];
- char** words = new char*[16];
- // 读入一行字符串
- cin.getline(buffer, 128);
- // 跳过开头的空白字符,找到第一个单词
- char* head = buffer;
- while (*head && isspace(*head)) {
- head++;
- }
- size_t word_idx = 0;
- words[word_idx++] = head;
- while (*head) {
- // 读第一个单词
- while (*head && !isspace(*head)) {
- head++;
- }
- // 跳过空白字符
- while (*head && isspace(*head)) {
- *head = '\0';
- head++;
- }
- words[word_idx++] = head;
- }
- // 输出单词数
- cout << word_idx - 1 << endl;
- // 读取输出顺序
- char* sequence = new char[word_idx];
- cin.getline(sequence, word_idx);
- // 输出单词
- for (size_t i = 0; i < word_idx - 1; i++) {
- cout << words[sequence[i] - '0'] << ' ';
- }
- cout << endl;
- delete[] buffer;
- delete[] words;
- delete[] sequence;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement