fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. istream &ifs = cin;
  6.  
  7. int nrows=1, ncols=0;
  8. string line;
  9. while (getline(ifs, line)) {
  10. int n=1;
  11. for (auto x: line) // count commas in the line
  12. if (x==',')
  13. n++;
  14. if (!ncols)
  15. ncols = n; // first line sets th enumber of columns
  16. else if (n == ncols) // subsequent lines increase the row count
  17. nrows++;
  18. else break; // unless the format does'n match anymore
  19. }
  20. cout <<nrows<<","<<ncols<<endl;
  21.  
  22. // your code goes here
  23. return 0;
  24. }
Success #stdin #stdout 0s 3472KB
stdin
-1,4,12,5.7
2.1,3,-10,3.3
7.1,1.11,12,10
stdout
3,4