fork(1) download
  1. #include <vector>
  2. #include <iostream>
  3. #include <unordered_map>
  4. using namespace std;
  5.  
  6. typedef unordered_map<string,size_t> strmap;
  7. typedef vector<bool> boolrow;
  8.  
  9. size_t regstring(strmap &sm,const string &str,size_t &id)
  10. {
  11. strmap::iterator smi=sm.find(str);
  12. if(smi!=sm.end()) return smi->second;
  13. sm[str]=id;
  14. return id++;
  15. }
  16.  
  17. int main()
  18. {
  19. size_t id=0,size,pairCount;
  20. cin>>size>>pairCount;
  21. vector<boolrow> tb(size,boolrow(size));
  22. strmap sm;
  23. while(pairCount--)
  24. {
  25. string sy,sx;
  26. cin>>ws>>sx>>sy;
  27. size_t y=regstring(sm,sy,id),x=regstring(sm,sx,id);
  28. tb[y][x]=true;
  29. }
  30. for(size_t y=0;y<size;++y,cout<<endl) for(size_t x=0;x<size;++x) cout<<(" "+!x)<<tb[y][x];
  31. return 0;
  32. }
Success #stdin #stdout 0s 3464KB
stdin
6 7
Adam Jola
Marcin Adam
Bartek Jola
Jola Ola
Bartek Darek
Ola Darek
Jola Marcin
stdout
0 1 0 1 0 0
0 0 1 0 0 0
1 0 0 0 0 0
0 0 0 0 0 0
1 0 0 0 0 0
0 0 0 1 1 0