Facebook
From Agacia, 5 Years ago, written in C++.
Embed
Download Paste or View Raw
Hits: 247
  1. // AKwBZ1.cpp : Defines the entry point for the console application.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include <iostream>
  6. #include <fstream>
  7. #include <stdio.h>
  8. #include <string>
  9. #include <sstream>
  10.  
  11. using namespace std;
  12.  
  13. int GRAPH[20][20] = {};
  14. int TOTV;
  15. void printGraph(int V)
  16. {
  17.         cout << "   ";
  18.         for (int b = 0; b < V; b++)
  19.                 cout << b + 1 << " ";
  20.         cout << endl;
  21.         for (int i = 0; i<V; i++)
  22.         {
  23.                 cout << i + 1 << "| ";
  24.                 for (int j = 0; j<V; j++)
  25.                 {
  26.                        
  27.                         cout << GRAPH[i][j] << " ";
  28.                 }
  29.                 cout << endl;
  30.         }
  31. }
  32.  
  33. void load()
  34. {
  35.         ifstream in;
  36.         int inV, outV;
  37.         int i = 0;
  38.         string line;
  39.                 in.open("data.txt");
  40.                 if (in.is_open())
  41.                 {
  42.                         getline(in, line);
  43.                         TOTV = stoi(line);
  44.                        
  45.                         while (in.good())
  46.                         {
  47.                                 getline(in, line);
  48.                                 stringstream ssin(line);
  49.                                 while (ssin.good()) {
  50.                                         ssin >> outV;
  51.                                         ssin >> inV;
  52.                                         GRAPH[outV-1][inV-1]++;
  53.                                 }
  54.                         }
  55.                 }
  56.                 else
  57.                 {
  58.                         cout << "Error loading";
  59.                 }
  60. }
  61.  
  62. int main()
  63. {
  64.         string cmd;
  65.         load();
  66.         printGraph(TOTV);
  67.         while (1)
  68.         {
  69.                 cout << "Input command: ";
  70.                 cin >> cmd;
  71.                 if (cmd == "exit" || cmd=="e")
  72.                         return 0;
  73.                 else if (cmd == "print")
  74.                         printGraph(TOTV);
  75.         }
  76.     return 0;
  77. }
  78.  
  79.  

Replies to akwb - odczyt rss

Title Name Language When
Re: akwb - odczyt Agacia cpp 5 Years ago.