fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. #define MAX_LINES 10000
  6. #define THRESHOLD 3.0 // ピーク閾値 [V]
  7. #define MIN_DISTANCE 50 // 最小サンプル間隔
  8.  
  9. typedef struct {
  10. double time;
  11. double voltage;
  12. } DataPoint;
  13.  
  14. int main(void) {
  15. DataPoint data[MAX_LINES];
  16. int count = 0;
  17.  
  18. while (count < MAX_LINES && scanf("%lf,%lf", &data[count].time, &data[count].voltage) == 2) {
  19. count++;
  20. }
  21.  
  22. printf("--- 解析結果 ---\n");
  23. printf("%-10s %-14s %-10s\n", "波形番号", "時刻[秒]", "電位[V]");
  24. printf("------------------------------\n");
  25.  
  26. int peak_index = 1;
  27. int last_peak_sample = -MIN_DISTANCE;
  28.  
  29. for (int i = 1; i < count - 1; i++) {
  30. if (data[i].voltage > data[i-1].voltage &&
  31. data[i].voltage >= data[i+1].voltage &&
  32. data[i].voltage >= THRESHOLD) {
  33.  
  34. if (i - last_peak_sample >= MIN_DISTANCE) {
  35. double v_rounded = round(data[i].voltage * 100.0) / 100.0;
  36. printf("%-10d %-14.2f %-10.2f\n", peak_index++, data[i].time, v_rounded);
  37. last_peak_sample = i;
  38. }
  39. }
  40. }
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 5324KB
stdin
3.640000,3.005813
3.650000,3.023631
3.660000,3.036357
3.670000,3.049084
3.680000,3.069447
3.690000,3.089809
3.700000,3.092355
3.710000,3.105082
3.720000,3.127990
3.730000,3.140716
3.740000,3.138171
3.750000,3.155988
3.760000,3.166170
3.770000,3.173806
3.780000,3.183987
3.790000,3.201804
3.800000,3.214531
3.810000,3.222167
3.820000,3.234894
3.830000,3.239985
3.840000,3.252711
3.850000,3.250166
3.860000,3.247621
3.870000,3.267983
3.880000,3.262893
3.890000,3.280710
3.900000,3.280710
3.910000,3.280710
3.920000,3.295982
3.930000,3.301073
3.940000,3.313799
3.950000,3.318890
3.960000,3.318890
3.970000,3.329072
3.980000,3.341798
3.990000,3.334162
4.000000,3.336708
4.010000,3.331617
4.020000,3.336708
4.030000,3.336708
4.040000,3.339253
4.050000,3.351980
4.060000,3.346889
4.070000,3.362161
4.080000,3.349434
4.090000,3.357070
4.100000,3.351980
4.110000,3.351980
4.120000,3.346889
4.130000,3.339253
4.140000,3.344344
4.150000,3.339253
4.160000,3.323981
4.170000,3.313799
4.180000,3.293437
4.190000,3.245075
4.200000,3.189078
4.210000,3.117808
4.220000,3.043993
4.230000,2.977814
4.240000,2.926908
4.250000,2.883637
4.260000,2.842911
4.270000,2.807277
4.280000,2.771642
4.290000,2.748734
4.300000,2.723280
4.310000,2.715644
4.320000,2.700372
4.330000,2.687646
4.340000,2.685100
4.350000,2.674919
4.360000,2.662192
4.370000,2.652011
4.380000,2.634193
4.390000,2.588377
4.400000,2.588377
4.410000,2.573105
4.420000,2.570560
4.430000,2.555288
4.440000,2.555288
4.450000,2.550197
4.460000,2.534925
stdout
--- 解析結果 ---
波形番号 時刻[秒]    電位[V] 
------------------------------
1          3.73           3.14