Language: C++

Last login: Sun Mar 18 21:58:19 on ttys000
Risa-no-MacBook:~ Risa$ cd Desktop/code/
Risa-no-MacBook:code Risa$ mkdir 2001
Risa-no-MacBook:code Risa$ cd 2001.cpp
-bash: cd: 2001.cpp: No such file or directory
Risa-no-MacBook:code Risa$ cd 2001
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
Risa-no-MacBook:2001 Risa$ ./2001
1 2 3
1 2 3
Segmentation fault: 11
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
2001.cpp:50:2: error: expected '}'
}
 ^
2001.cpp:6:14: note: to match this '{'
struct lines {
             ^
2001.cpp:17:12: error: member reference type 'lines' is not a pointer; did you mean to use '.'?
  sort(line->begin(), line->end(), greater<lines>());
       ~~~~^~
           .
2001.cpp:17:14: error: no member named 'begin' in 'lines'
  sort(line->begin(), line->end(), greater<lines>());
       ~~~~  ^
2001.cpp:17:27: error: member reference type 'lines' is not a pointer; did you mean to use '.'?
  sort(line->begin(), line->end(), greater<lines>());
                      ~~~~^~
                          .
2001.cpp:17:29: error: no member named 'end' in 'lines'
  sort(line->begin(), line->end(), greater<lines>());
                      ~~~~  ^
2001.cpp:19:27: error: no member named 'size' in 'lines'
  for(int i = 0; i < line.size(); i++) { 
                     ~~~~ ^
2001.cpp:20:12: error: type 'lines' does not provide a subscript operator
    if(line[i].p == a){
       ~~~~^~
2001.cpp:21:15: error: type 'lines' does not provide a subscript operator
      a = line[i].q;
          ~~~~^~
2001.cpp:22:18: error: type 'lines' does not provide a subscript operator
    }else if(line[i].q == a){
             ~~~~^~
2001.cpp:23:15: error: type 'lines' does not provide a subscript operator
      a = line[i].p;
          ~~~~^~
2001.cpp:46:28: error: no viable conversion from 'value_type *' (aka 'lines *') to 'lines'
    cout << amida(n, m, a, &line.front());
                           ^~~~~~~~~~~~~
2001.cpp:6:8: note: candidate constructor (the implicit copy constructor) not viable: no known
      conversion from 'value_type *' (aka 'lines *') to 'const lines &' for 1st argument; remove &
struct lines {
       ^
2001.cpp:14:38: note: passing argument to parameter 'line' here
int amida(int n, int m, int a, lines line) {
                                     ^
2001.cpp:50:2: error: expected ';' after struct
}
 ^
 ;
12 errors generated.
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
2001.cpp:50:2: error: expected '}'
}
 ^
2001.cpp:6:14: note: to match this '{'
struct lines {
             ^
2001.cpp:17:14: error: no member named 'begin' in 'lines'
  sort(line->begin(), line->end(), greater<lines>());
       ~~~~  ^
2001.cpp:17:29: error: no member named 'end' in 'lines'
  sort(line->begin(), line->end(), greater<lines>());
                      ~~~~  ^
2001.cpp:19:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
  for(int i = 0; i < line.size(); i++) { 
                     ~~~~^
                         ->
2001.cpp:19:27: error: no member named 'size' in 'lines'
  for(int i = 0; i < line.size(); i++) { 
                     ~~~~ ^
2001.cpp:50:2: error: expected ';' after struct
}
 ^
 ;
6 errors generated.
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
2001.cpp:18:12: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
  sort(line.begin(), line.end(), greater<lines>());
       ~~~~^
           ->
2001.cpp:18:13: error: no member named 'begin' in 'lines'
  sort(line.begin(), line.end(), greater<lines>());
       ~~~~ ^
2001.cpp:18:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
  sort(line.begin(), line.end(), greater<lines>());
                     ~~~~^
                         ->
2001.cpp:18:27: error: no member named 'end' in 'lines'
  sort(line.begin(), line.end(), greater<lines>());
                     ~~~~ ^
2001.cpp:20:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
  for(int i = 0; i < line.size(); i++) { 
                     ~~~~^
                         ->
2001.cpp:20:27: error: no member named 'size' in 'lines'
  for(int i = 0; i < line.size(); i++) { 
                     ~~~~ ^
6 errors generated.
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
2001.cpp:18:14: error: no member named 'begin' in 'lines'
  sort(line->begin(), line->end(), greater<lines>());
       ~~~~  ^
2001.cpp:18:29: error: no member named 'end' in 'lines'
  sort(line->begin(), line->end(), greater<lines>());
                      ~~~~  ^
2001.cpp:20:28: error: no member named 'size' in 'lines'
  for(int i = 0; i < line->size(); i++) { 
                     ~~~~  ^
3 errors generated.
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
Risa-no-MacBook:2001 Risa$ ./2001
4 4 1
3 1 2
2 2 3
3 3 4
1 3 4
4
0 0 0
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
Risa-no-MacBook:2001 Risa$ ./2001
2 1 2
1 1 2
1
10 10 2
7 6 7
9 2 3
4 6 7
9 4 5
5 8 9
10 4 5
9 9 10
8 1 2
8 3 4
1 2 3
4
10 10 1
2 2 3
8 5
^C
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
Risa-no-MacBook:2001 Risa$ ./2001
4 4 1               
3 1 2
2 2 3
3 3 4
1 3 4
4
2 1 2   
1 1 2
1
0 0 0
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
Risa-no-MacBook:2001 Risa$ ./2001
4 4 1
3 1 2
2 2 3
3 3 4
1 3 4
4
2 1 2
1 1 2
2
0 0 0
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
Risa-no-MacBook:2001 Risa$ ./2001
2 1 2
1 1 2
1
2 1 2
1 1 2
2
^C
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp
Risa-no-MacBook:2001 Risa$ g++ -o 2001 2001.cpp
Risa-no-MacBook:2001 Risa$ ./2001
2 1 2
1 1 2
1
2 1 2
1 1 2
1
4 4 1 
3 1 2
2 2 3
3 3 4
1 3 4
4
4 4 1
3 1 2
2 2 3
3 3 4
1 3 4
4
0 0 0
Risa-no-MacBook:2001 Risa$ emacs 2001.cpp

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct lines {
  int h;  //横線の高さ                                                            
  int p, q; //横線に繋がる縦線の番号                                              

  bool operator>(const lines &left) const {
    return h > left.h;
  }
};

int amida(int n, int m, int a, lines* line, int size) {
  for(unsigned int i = 0; i < size; ++i) {
    if(line[i].p == a)
      a = line[i].q;
    else if(line[i].q == a)
      a = line[i].p;
  }
  return a;
}

int main() {
  int n; //縦線の本数                                                             
  int m; //横線の本数                                                             
  int a; //調べる縦線の番号                                                       
  vector<lines> line;

  while(1) {
    cin >> n >> m >> a;
    if(n == 0 && m == 0 && a == 0) break;

    for(int i = 0; i < m; ++i) {
      lines l;
      cin >> l.h >> l.p >> l.q;
      line.push_back(l);
    }

    sort(line.begin(), line.end(), greater<lines>());
    cout << amida(n, m, a, &line.front(), line.size()) << endl;
    line.clear();
  }

  return 0;
}




Compiler output:
a.cc:21:46: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   21 | 2001.cpp:17:12: error: member reference type 'lines' is not a pointer; did you mean to use '.'?
      |                                              ^~~~~~~
a.cc:25:40: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   25 | 2001.cpp:17:14: error: no member named 'begin' in 'lines'
      |                                        ^~~~~~~
a.cc:25:51: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   25 | 2001.cpp:17:14: error: no member named 'begin' in 'lines'
      |                                                   ^~~~~~~
a.cc:28:46: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   28 | 2001.cpp:17:27: error: member reference type 'lines' is not a pointer; did you mean to use '.'?
      |                                              ^~~~~~~
a.cc:32:40: warning: multi-character character constant [-Wmultichar]
   32 | 2001.cpp:17:29: error: no member named 'end' in 'lines'
      |                                        ^~~~~
a.cc:32:49: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   32 | 2001.cpp:17:29: error: no member named 'end' in 'lines'
      |                                                 ^~~~~~~
a.cc:35:40: warning: multi-character character constant [-Wmultichar]
   35 | 2001.cpp:19:27: error: no member named 'size' in 'lines'
      |                                        ^~~~~~
a.cc:35:50: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   35 | 2001.cpp:19:27: error: no member named 'size' in 'lines'
      |                                                  ^~~~~~~
a.cc:38:29: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   38 | 2001.cpp:20:12: error: type 'lines' does not provide a subscript operator
      |                             ^~~~~~~
a.cc:41:29: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   41 | 2001.cpp:21:15: error: type 'lines' does not provide a subscript operator
      |                             ^~~~~~~
a.cc:44:29: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   44 | 2001.cpp:22:18: error: type 'lines' does not provide a subscript operator
      |                             ^~~~~~~
a.cc:47:29: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   47 | 2001.cpp:23:15: error: type 'lines' does not provide a subscript operator
      |                             ^~~~~~~
a.cc:50:50: warning: multi-character literal with 12 characters exceeds 'int' size of 4 bytes
   50 | 2001.cpp:46:28: error: no viable conversion from 'value_type *' (aka 'lines *') to 'lines'
      |                                                  ^~~~~~~~~~~~~~
a.cc:50:70: warning: multi-character literal with 7 characters exceeds 'int' size of 4 bytes
   50 | 2001.cpp:46:28: error: no viable conversion from 'value_type *' (aka 'lines *') to 'lines'
      |                                                                      ^~~~~~~~~
a.cc:50:84: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   50 | 2001.cpp:46:28: error: no viable conversion from 'value_type *' (aka 'lines *') to 'lines'
      |                                                                                    ^~~~~~~
a.cc:54:23: warning: multi-character literal with 12 characters exceeds 'int' size of 4 bytes
   54 |       conversion from 'value_type *' (aka 'lines *') to 'const lines &' for 1st argument; remove &
      |                       ^~~~~~~~~~~~~~
a.cc:54:43: warning: multi-character literal with 7 characters exceeds 'int' size of 4 bytes
   54 |       conversion from 'value_type *' (aka 'lines *') to 'const lines &' for 1st argument; remove &
      |                                           ^~~~~~~~~
a.cc:54:57: warning: multi-character literal with 13 characters exceeds 'int' size of 4 bytes
   54 |       conversion from 'value_type *' (aka 'lines *') to 'const lines &' for 1st argument; remove &
      |                                                         ^~~~~~~~~~~~~~~
a.cc:57:53: warning: multi-character character constant [-Wmultichar]
   57 | 2001.cpp:14:38: note: passing argument to parameter 'line' here
      |                                                     ^~~~~~
a.cc:73:40: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   73 | 2001.cpp:17:14: error: no member named 'begin' in 'lines'
      |                                        ^~~~~~~
a.cc:73:51: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   73 | 2001.cpp:17:14: error: no member named 'begin' in 'lines'
      |                                                   ^~~~~~~
a.cc:76:40: warning: multi-character character constant [-Wmultichar]
   76 | 2001.cpp:17:29: error: no member named 'end' in 'lines'
      |                                        ^~~~~
a.cc:76:49: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   76 | 2001.cpp:17:29: error: no member named 'end' in 'lines'
      |                                                 ^~~~~~~
a.cc:79:46: warning: multi-character literal with 7 characters exceeds 'int' size of 4 bytes
   79 | 2001.cpp:19:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
      |                                              ^~~~~~~~~
a.cc:79:90: warning: multi-character character constant [-Wmultichar]
   79 | 2001.cpp:19:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
      |                                                                                          ^~~~
a.cc:83:40: warning: multi-character character constant [-Wmultichar]
   83 | 2001.cpp:19:27: error: no member named 'size' in 'lines'
      |                                        ^~~~~~
a.cc:83:50: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   83 | 2001.cpp:19:27: error: no member named 'size' in 'lines'
      |                                                  ^~~~~~~
a.cc:94:46: warning: multi-character literal with 7 characters exceeds 'int' size of 4 bytes
   94 | 2001.cpp:18:12: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
      |                                              ^~~~~~~~~
a.cc:94:90: warning: multi-character character constant [-Wmultichar]
   94 | 2001.cpp:18:12: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
      |                                                                                          ^~~~
a.cc:98:40: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   98 | 2001.cpp:18:13: error: no member named 'begin' in 'lines'
      |                                        ^~~~~~~
a.cc:98:51: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
   98 | 2001.cpp:18:13: error: no member named 'begin' in 'lines'
      |                                                   ^~~~~~~
a.cc:101:46: warning: multi-character literal with 7 characters exceeds 'int' size of 4 bytes
  101 | 2001.cpp:18:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
      |                                              ^~~~~~~~~
a.cc:101:90: warning: multi-character character constant [-Wmultichar]
  101 | 2001.cpp:18:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
      |                                                                                          ^~~~
a.cc:105:40: warning: multi-character character constant [-Wmultichar]
  105 | 2001.cpp:18:27: error: no member named 'end' in 'lines'
      |                                        ^~~~~
a.cc:105:49: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
  105 | 2001.cpp:18:27: error: no member named 'end' in 'lines'
      |                                                 ^~~~~~~
a.cc:108:46: warning: multi-character literal with 7 characters exceeds 'int' size of 4 bytes
  108 | 2001.cpp:20:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
      |                                              ^~~~~~~~~
a.cc:108:90: warning: multi-character character constant [-Wmultichar]
  108 | 2001.cpp:20:26: error: member reference type 'lines *' is a pointer; did you mean to use '->'?
      |                                                                                          ^~~~
a.cc:112:40: warning: multi-character character constant [-Wmultichar]
  112 | 2001.cpp:20:27: error: no member named 'size' in 'lines'
      |                                        ^~~~~~
a.cc:112:50: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
  112 | 2001.cpp:20:27: error: no member named 'size' in 'lines'
      |                                                  ^~~~~~~
a.cc:118:40: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
  118 | 2001.cpp:18:14: error: no member named 'begin' in 'lines'
      |                                        ^~~~~~~
a.cc:118:51: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
  118 | 2001.cpp:18:14: error: no member named 'begin' in 'lines'
      |                                                   ^~~~~~~
a.cc:121:40: warning: multi-character character constant [-Wmultichar]
  121 | 2001.cpp:18:29: error: no member named 'end' in 'lines'
      |                                        ^~~~~
a.cc:121:49: warning: multi-character literal with 5 characters exceeds 'int' size of 4 bytes
  121 | 2001.cpp:18:29: error: no member named 'end' in 'lines'
      |                                                 ^~~~~~~
a.cc:124:40: warning: multi-character character constant [-Wmultichar]
  124 | 2001.cpp:20:28: error: no member named 'size' in 'lines'
      |                                        ^~~~~~
a.cc:124:50: warning: multi-character literal with 5 cha