PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree(一)

简介: PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree

1164 Good in C

描述

When your interviewer asks you to write “Hello World” using C, can you do as the following figure shows?

Input Specification:

Each input file contains one test case. For each case, the first part gives the 26 capital English letters A-Z, each in a 7×5 matrix of C’s and .'s. Then a sentence is given in a line, ended by a return. The sentence is formed by several words (no more than 10 continuous capital English letters each), and the words are separated by any characters other than capital English letters.

It is guaranteed that there is at least one word given.

Output Specification:

For each word, print the matrix form of each of its letters in a line, and the letters must be separated by exactly one column of space. There must be no extra space at the beginning or the end of the word.

Between two adjacent words, there must be a single empty line to separate them. There must be no extra line at the beginning or the end of the output.

Sample Input:

..C..
.C.C.
C...C
CCCCC
C...C
C...C
C...C
CCCC.
C...C
C...C
CCCC.
C...C
C...C
CCCC.
.CCC.
C...C
C....
C....
C....
C...C
.CCC.
CCCC.
C...C
C...C
C...C
C...C
C...C
CCCC.
CCCCC
C....
C....
CCCC.
C....
C....
CCCCC
CCCCC
C....
C....
CCCC.
C....
C....
C....
CCCC.
C...C
C....
C.CCC
C...C
C...C
CCCC.
C...C
C...C
C...C
CCCCC
C...C
C...C
C...C
CCCCC
..C..
..C..
..C..
..C..
..C..
CCCCC
CCCCC
....C
....C
....C
....C
C...C
.CCC.
C...C
C..C.
C.C..
CC...
C.C..
C..C.
C...C
C....
C....
C....
C....
C....
C....
CCCCC
C...C
C...C
CC.CC
C.C.C
C...C
C...C
C...C
C...C
C...C
CC..C
C.C.C
C..CC
C...C
C...C
.CCC.
C...C
C...C
C...C
C...C
C...C
.CCC.
CCCC.
C...C
C...C
CCCC.
C....
C....
C....
.CCC.
C...C
C...C
C...C
C.C.C
C..CC
.CCC.
CCCC.
C...C
CCCC.
CC...
C.C..
C..C.
C...C
.CCC.
C...C
C....
.CCC.
....C
C...C
.CCC.
CCCCC
..C..
..C..
..C..
..C..
..C..
..C..
C...C
C...C
C...C
C...C
C...C
C...C
.CCC.
C...C
C...C
C...C
C...C
C...C
.C.C.
..C..
C...C
C...C
C...C
C.C.C
CC.CC
C...C
C...C
C...C
C...C
.C.C.
..C..
.C.C.
C...C
C...C
C...C
C...C
.C.C.
..C..
..C..
..C..
..C..
CCCCC
....C
...C.
..C..
.C...
C....
CCCCC
HELLO~WORLD!

Sample Output:

C...C CCCCC C.... C.... .CCC.
C...C C.... C.... C.... C...C
C...C C.... C.... C.... C...C
CCCCC CCCC. C.... C.... C...C
C...C C.... C.... C.... C...C
C...C C.... C.... C.... C...C
C...C CCCCC CCCCC CCCCC .CCC.
C...C .CCC. CCCC. C.... CCCC.
C...C C...C C...C C.... C...C
C...C C...C CCCC. C.... C...C
C.C.C C...C CC... C.... C...C
CC.CC C...C C.C.. C.... C...C
C...C C...C C..C. C.... C...C
C...C .CCC. C...C CCCCC CCCC.

每一行行末不能多空格!!!

最后一行也不能多空行!!!

可能最后的输入字母也会有空格,所以不能用cin>>str,只能getline(cin,str)

第一个字符可能不是大写字母,需要特判一下

代码

#include<iostream>
#include<cstring>
#include<map>
#include<cctype>
#include<vector>
using namespace std;
vector<vector<string>> m;
int main() {
  for (int i = 0; i < 26; i++) {
    vector<string> vs;
    string s;
    for (int j = 0; j < 7; j++) {
      cin >> s;
      vs.push_back(s);
    }
    m.push_back(vs);
  }
  string str;
  cin.ignore();
  getline(cin, str);
  vector<string> sb(7);
  int len = str.length();
  int flag = 1;
  for (int i = 0; i < len; i++) {
    if (str[i] >= 'A' && str[i] <= 'Z') {
      for (int j = 0; j < 7; j++)
        sb[j]+= m[str[i]-'A'][j] + " ";
    }
    else if (sb[0]!=""){
      flag--;
      if (flag < 0)
        cout << endl<<endl;
      for (int j = 0; j < 6; j++)
        cout << sb[j].substr(0,sb[j].length()-1) << endl;
      cout << sb[6].substr(0,sb[6].length()-1);
      for (int j = 0; j < 7; j++)
        sb[j] = "";
    }
  }
  if (sb[0]!="") {
    flag--;
    if (flag < 0)
      cout << endl << endl;
    for (int j = 0; j < 6; j++)
      cout << sb[j].substr(0,sb[j].length()-1) << endl;
    cout << sb[6].substr(0,sb[6].length()-1);
  }
  return 0;
}

1165 Block Reversing

Given a singly linked list L LL. Let us consider every K KK nodes as a block (if there are less than K KK nodes at the end of the list, the rest of the nodes are still considered as a block). Your job is to reverse all the blocks in L LL. For example, given L LL as 1 → 2 → 3 → 4 → 5 → 6 → 7 → 8 1→2→3→4→5→6→7→812345678 and K KK as 3 33, your output must be 7 → 8 → 4 → 5 → 6 → 1 → 2 → 3 7→8→4→5→6→1→2→378456123.

Input Specification:

Each input file contains one test case. For each case, the first line contains the address of the first node, a positive N ( ≤ 1 0 5 ) N (≤10^5)N(105) which is the total number of nodes, and a positive K ( ≤ N ) K (≤N)K(N) which is the size of a block. The address of a node is a 5 55-digit nonnegative integer, and NULL is represented by − 1 −11.

Then N NN lines follow, each describes a node in the format:

Address Data Next

where Address is the position of the node, Data is an integer, and Next is the position of the next node.


目录
相关文章
Educational Codeforces Round 113 (Rated for Div. 2)A. Balanced Substring
Educational Codeforces Round 113 (Rated for Div. 2)A. Balanced Substring
88 0
|
机器学习/深度学习 网络架构
PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree(二)
PTA 1164-1167 Good in C/Block Reversing/Summit/Cartesian Tree
117 0
|
人工智能
codeforces 1092——F:Tree with Maximum Cost (树上DP)
codeforces 1092——F:Tree with Maximum Cost (树上DP)
118 0
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
AtCoder Beginner Contest 214 D.Sum of Maximum Weights (思维 并查集)
115 0
|
人工智能
Educational Codeforces Round 98 (Rated for Div. 2)B-Toy Blocks
You are asked to watch your nephew who likes to play with toy blocks in a strange way. He has n boxes and the i-th box has ai blocks. His game consists of two steps: he chooses an arbitrary box i; he tries to move all blocks from the i-th box to other boxes.
260 0
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
Data Structures and Algorithms (English) - 6-16 Shortest Path [3](25 分)
103 0
Data Structures and Algorithms (English) - 6-11 Shortest Path [2](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [2](25 分)
124 0
Data Structures and Algorithms (English) - 6-17 Shortest Path [4](25 分)
Data Structures and Algorithms (English) - 6-17 Shortest Path [4](25 分)
108 0
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
Data Structures and Algorithms (English) - 6-11 Shortest Path [1](25 分)
114 0
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
Data Structures and Algorithms (English) - 6-13 Topological Sort(25 分)
109 0