fork download
  1. #include <stdio.h>
  2.  
  3. #define MAX_DATA 20000
  4.  
  5. int main(void) {
  6. double time[MAX_DATA];
  7. double voltage[MAX_DATA];
  8. int count = 0;
  9.  
  10. while(scanf ("%lf,%lf", &time[count], &voltage[count]) == 2){
  11. count++;
  12.  
  13. if(count >= MAX_DATA){
  14. printf("警告:データ数が配列の最大値を超えました。\n");
  15. break;
  16. }
  17. }
  18. printf("--- ピーク検出結果 ---\n");
  19. printf("波形番号\t時刻[秒]\t電位[V]\n");
  20.  
  21. int peak_count = 1;
  22. double threshold = 3.5;
  23.  
  24. for(int i = 1; i<count - 1; i++){
  25. if(voltage[i] > voltage[i-1] && voltage[i] > voltage[i+1] && voltage[i] > threshold){
  26. printf("%d\t\t%.2f\t\t%.2f\n", peak_count, time[i], voltage[i]);
  27. peak_count++;
  28. }
  29. }
  30. if(peak_count == 1){
  31. printf("指定された閾値(%.2fV)を超えるピークは見つかりませんでした。\n", threshold);
  32. }
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0s 5320KB
stdin
0.000000,3.246368
0.100000,3.248917
0.200000,3.256561
0.300000,3.256561
0.400000,3.241272
0.500000,3.243820
0.600000,3.241272
0.700000,3.248917
0.800000,3.256561
0.900000,3.246368
1.000000,3.248917
1.100000,3.254013
1.200000,3.254013
1.300000,3.256561
1.400000,3.248917
1.500000,3.256561
1.600000,3.254013
1.700000,3.246368
1.800000,3.246368
1.900000,3.248917
2.000000,3.246368
2.100000,3.248917
2.200000,3.246368
2.300000,3.246368
2.400000,3.248917
2.500000,3.248917
2.600000,3.248917
2.700000,3.248917
2.800000,3.248917
2.900000,3.246368
3.000000,3.248917
3.100000,3.246368
3.200000,3.254013
3.300000,3.254013
3.400000,3.254013
3.500000,3.248917
3.600000,3.251465
3.700000,3.256561
3.800000,3.282043
3.900000,3.276946
4.000000,3.320265
4.100000,3.411999
4.200000,3.419644
4.300000,3.440029
4.400000,3.437481
4.500000,3.595468
4.600000,3.768743
4.700000,3.847736
4.800000,3.880862
4.900000,3.916537
5.000000,3.924181
5.100000,3.931826
5.200000,3.929278
5.300000,3.944567
5.400000,3.952211
5.500000,3.959856
5.600000,3.949663
5.700000,3.954759
5.800000,3.964952
5.900000,3.962404
6.000000,3.998078
6.100000,3.985337
6.200000,3.977693
6.300000,4.021012
6.400000,4.033753
6.500000,3.972597
6.600000,3.827351
6.700000,3.682105
6.800000,3.554697
6.900000,3.478252
7.000000,3.417096
7.100000,3.442577
7.200000,3.633690
7.300000,3.812062
7.400000,3.913989
7.500000,3.947115
7.600000,4.013367
7.700000,4.056686
7.800000,4.105101
7.900000,4.125487
8.000000,4.138227
8.100000,4.145872
8.200000,4.140776
8.300000,4.092360
8.400000,3.975145
8.500000,3.776388
8.600000,3.684653
8.700000,3.575082
8.800000,3.526667
8.900000,3.465511
9.000000,3.465511
9.100000,3.457866
9.200000,3.569986
9.300000,3.725424
9.400000,3.896151
9.500000,3.995530
9.600000,4.077071
9.700000,4.158613
9.800000,4.145872
9.900000,4.120390
10.000000,4.089812
10.100000,3.707587
10.200000,3.541956
10.300000,3.488444
10.400000,3.498637
10.500000,3.687202
10.600000,3.931826
10.700000,4.031204
10.800000,4.084716
10.900000,4.150968
stdout
--- ピーク検出結果 ---
波形番号	時刻[秒]	電位[V]
1		5.10		3.93
2		5.50		3.96
3		5.80		3.96
4		6.00		4.00
5		6.40		4.03
6		8.10		4.15
7		9.70		4.16