CSES - Datatähti 2020 alku - Results
Submission details
Task:Merkkijonot
Sender:jusola
Submission time:2019-10-02 21:11:34 +0300
Language:C++11
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'bool isPair(std::__cxx11::string, std::__cxx11::string)':
input/code.cpp:32:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = 0; i < a.length() + 1; i++){
                   ~~^~~~~~~~~~~~~~~~
input/code.cpp:34:12: error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream<char>}' and 'std::map<char, char>::iterator {aka std::_Rb_tree_iterator<std::pair<const char, char> >}')
       cout << mapA.find(arrA[i]);
       ~~~~~^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/7/iostream:39:0,
                 from input/code.cpp:1:
/usr/include/c++/7/ostream:108:7: note: candidate: std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(std::basic_ostream<_CharT, _Traits>::__ostream_type& (*)(std::basic_ostream<_CharT, _Traits>::__ostream_type&)) [with _CharT = char; _Traits = std::char_traits<char>; std::basic_ostream<_...

Code

#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
#include <algorithm>
#include <iterator>
#include <bits/stdc++.h>
#include <unordered_map>

using namespace std;


const string alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

char alphabetArr[52];

bool isPair(string a, string b){
  map<char, char> mapA;
  map<char, char> mapB;

  std::map<char, char>::iterator it;

  char arrA[a.length() + 1];
  char arrB[b.length() + 1];

  string newA;
  string newB;

  strcpy(arrA, a.c_str());
  strcpy(arrB, b.c_str());

  for (int i = 0; i < a.length() + 1; i++){
    if(mapA.find(arrA[i]) != mapA.end()){
      cout << mapA.find(arrA[i]);
      newA = newA + std::string(1, 'a');
    }else{
      newA = newA + std::string(1, 'a');
      mapA.insert(std::pair<char,char>(alphabetArr[mapA.size()], end(mapA)));

    }
  }

  for (int i = 0; i < b.length() + 1; i++){
    it = mapB.find(arrB[i]);
    if(it != mapB.end()){
      newB += string(1, 'a');
    }else{
      newB += string(1, 'a');
      mapB.insert(alphabetArr[mapB.size()], mapB.end());
    }
  }
}


int main(){
  int num;
  int amount = 0;
  cin >> num;



  strcpy(alphabetArr, alphabet.c_str());

  string arr[num];
  for (int i = 0; i < num; i++){
    cin >> arr[i];
  }
  for (int i = 0; i < num; i++){
    for (int j = 0; j < num; j++){
      if(isPair(arr[i], arr[j])){
        amount++;
      }
    }
  }
  cout << amount/2; //Jaetaan kahdella, koska jokainen käydään läpi 2 kertaa
  return 0;
}