fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <numeric>
  5. #include <iomanip>
  6.  
  7. struct PowerData {
  8. std::vector<int> PowerOutput;
  9. std::vector<int> PowerString2;
  10. };
  11.  
  12. struct InverterData {
  13. std::string serialNumber;
  14. std::string date;
  15. PowerData plotData;
  16. };
  17.  
  18. double calculateEfficiency(const PowerData& data) {
  19. double totalAC = std::accumulate(data.PowerOutput.begin(), data.PowerOutput.end(), 0);
  20. double totalDC = std::accumulate(data.PowerString2.begin(), data.PowerString2.end(), 0);
  21.  
  22. if (totalDC == 0) return 0.0; // Unikaj dzielenia przez zero
  23. return (totalAC / totalDC) * 100.0;
  24. }
  25.  
  26. double calculateEnergyInKWh(const std::vector<int>& powerData) {
  27. double energy = 0.0;
  28. for (size_t i = 0; i < powerData.size(); ++i) {
  29. energy += (powerData[i] / 1000.0) * (15.0 / 60.0); // Moc w kW * czas w godzinach
  30. }
  31. return energy;
  32. }
  33.  
  34. int main() {
  35. // Przykładowe dane wejściowe
  36. InverterData inverter = {
  37. "452/21", // S/N
  38. "2025-02-21", // Data
  39. { // PlotData
  40. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 48, 145, 177, 434, 1126, 1387, 1553, 1684, 1798, 1894, 1999, 2068, 2142, 2204, 2249, 2251, 2276, 2262, 2236, 1993, 2008, 1989, 1971, 1902, 1806, 1686, 1529, 1347, 1096, 1218, 1088, 917, 778, 620, 459, 276, 239, 156, 88, 38, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, // PowerOutput
  41. {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 129, 251, 280, 518, 1189, 1466, 1646, 1768, 1891, 2026, 2096, 2172, 2244, 2336, 2395, 2399, 2447, 2398, 2364, 2138, 2145, 2107, 2093, 2023, 1910, 1792, 1630, 1447, 1195, 1312, 1164, 1003, 858, 741, 564, 366, 323, 252, 175, 137, 15, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} // PowerString2
  42. }
  43. };
  44.  
  45. // Obliczenia
  46. double efficiency = calculateEfficiency(inverter.plotData);
  47. double energyInKWh = calculateEnergyInKWh(inverter.plotData.PowerOutput);
  48.  
  49. // Wyświetlanie wyników
  50. std::cout << "Typ falownika PS100: " << inverter.serialNumber << std::endl;
  51. std::cout << "Data: " << inverter.date << std::endl;
  52. std::cout << "Energia w wybranym dniu: " << std::fixed << std::setprecision(2) << energyInKWh << " kWh" << std::endl;
  53. std::cout << "Sprawność falownika: " << std::fixed << std::setprecision(2) << efficiency << "%" << std::endl;
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5284KB
stdin
/*  Berechnung des Hamming-Abstandes zwischen zwei 128-Bit Werten in 	*/
/*	einer Textdatei. 													*/
/*  Die Werte müssen auf einer separaten Zeile gespeichert sein			*/
/* 																		*/
/*	Erstellt: 17.5.2010													*/
/*  Autor: Thomas Scheffler												*/

#include <stdio.h>
#include <stdlib.h>

#define ARRAY_SIZE 32

unsigned Hamdist(unsigned x, unsigned y)
{
  unsigned dist = 0, val = x ^ y;
 
  // Count the number of set bits
  while(val)
  {
    ++dist; 
    val &= val - 1;
  }
 
  return dist;
}



int main (void)
{
	char hex;
	int i;
	int a[ARRAY_SIZE];
	int b[ARRAY_SIZE];
	int hamDist = 0;
	FILE* fp;
	
	//Arrays mit 0 initialisieren
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
  		a[i] = 0;
  		b[i] = 0;
	}

	
	fp = fopen("hex.txt","r");
	if (fp == NULL) 
	{
		printf("Die Datei hex.txt wurde nicht gefunden!");
		exit(EXIT_FAILURE);
	}

	i=0;
	printf("1.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
        a[i]=strtol(&hex,0,16);
		i++;
    }
	i=0;
	printf("2.Zeile einlesen.\n");

 	while((hex=fgetc(fp))!='\n' && hex != EOF)
    {
    	b[i]=strtol(&hex,0,16);
        i++;
    }
	fclose(fp);

	printf("Hamming-Abweichung pro Nibble:\n");
	for (i = 0; i < ARRAY_SIZE; ++i)
	{
		printf ("%i\t%i\t%i\n",a[i],b[i],Hamdist(a[i],b[i]));
		hamDist += Hamdist(a[i],b[i]);
	}
	printf ("\nHamming-Abweichung der Hash-Werte:%d\n",hamDist);
}

stdout
Typ falownika PS100: 452/21
Data: 2025-02-21
Energia w wybranym dniu: 13.28 kWh
Sprawność falownika: 92.54%