View Code of Problem 7

#include<iostream>
#include<map>
using namesapce std;
int main() {
	int case_count;
	int rule_count;
	int query_count;
	int query;
	int a, b;
	map<int, int> dic;
	cin >> case_count;
	for (int i = 0; i< case_count; ++i) {
		cin >> rule_count;
		for (int j = 0; j<rule_count; ++j) {
			scanf("%d=%d", &a, &b);
			dic[a] = b;
			dic[b] = a;
		}
		cin >> query_count;
		for (int j = 0; j < query_count; ++j) {
			cin >> query;
			map<int, int>::iterator result = dic.find(query);
			if (result != dic.end())
				cout << result->second << endl;
			else cout << "UNKNOW" << endl;
		}
		cout << endl;
	}
	return 0;
}
/*
Main.cc:3:7: error: expected nested-name-specifier before 'namesapce'
 using namesapce std;
       ^
Main.cc: In function 'int main()':
Main.cc:10:2: error: 'map' was not declared in this scope
  map<int, int> dic;
  ^
Main.cc:10:2: note: suggested alternative:
In file included from /usr/include/c++/4.9/map:61:0,
                 from Main.cc:2:
/usr/include/c++/4.9/bits/stl_map.h:96:11: note:   'std::map'
     class map
           ^
Main.cc:10:6: error: expected primary-expression before 'int'
  map<int, int> dic;
      ^
Main.cc:11:2: error: 'cin' was not declared in this scope
  cin >> case_count;
  ^
Main.cc:11:2: note: suggested alternative:
In file included from Main.cc:1:0:
/usr/include/c++/4.9/iostream:60:18: note:   'std::cin'
   extern istream cin;  /// Linked to standard input
                  ^
Main.cc:16:4: error: 'dic' was not declared in this scope
    dic[a] = b;
    ^
Main.cc:22:8: error: expected primary-expression before 'int'
    map<int, int>::iterator result = dic.find(query);
        ^
Main.cc:23:8: error: 'result' was not declared in this scope
    if (result != dic.end())
        ^
Main.cc:23:18: error: 'dic' was not declared in this scope
    if (result != dic.end())
                  ^
Main.cc:24:5: error: 'cout' was not declared in this scope
     cout << result->second << endl;
     ^
Main.cc:24:5: note: suggested alternative:
In file included from Main.cc:1:0:
/usr/include/c++/4.9/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^
Main.cc:24:31: error: 'endl' was not declared in this scope
     cout << result->second << endl;
                               ^
Main.cc:24:31: note: suggested alternative:
In file included from /usr/include/c++/4.9/iostream:39:0,
                 from Main.cc:1:
/usr/include/c++/4.9/ostream:564:5: note:   'std::endl'
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^
Main.cc:25:9: error: 'cout' was not declared in this scope
    else cout << "UNKNOW" << endl;
         ^
Main.cc:25:9: note: suggested alternative:
In file included from Main.cc:1:0:
/usr/include/c++/4.9/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^
Main.cc:25:29: error: 'endl' was not declared in this scope
    else cout << "UNKNOW" << endl;
                             ^
Main.cc:25:29: note: suggested alternative:
In file included from /usr/include/c++/4.9/iostream:39:0,
                 from Main.cc:1:
/usr/include/c++/4.9/ostream:564:5: note:   'std::endl'
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^
Main.cc:27:3: error: 'cout' was not declared in this scope
   cout << endl;
   ^
Main.cc:27:3: note: suggested alternative:
In file included from Main.cc:1:0:
/usr/include/c++/4.9/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^
Main.cc:27:11: error: 'endl' was not declared in this scope
   cout << endl;
           ^
Main.cc:27:11: note: suggested alternative:
In file included from /usr/include/c++/4.9/iostream:39:0,
                 from Main.cc:1:
/usr/include/c++/4.9/ostream:564:5: note:   'std::endl'
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^
*/

Double click to view unformatted code.


Back to problem 7