fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. const int MN = 105;
  5. char board[MN][MN];
  6. int main()
  7. {
  8. int n;
  9. cin >> n;
  10. for(int i = 0; i < n; ++i) cin >> board[i];
  11. long long ans = 0;
  12. for(int i = 0; i < n; ++i){
  13. int cnt = 0;
  14. for(int j = 0; j < n; ++j){
  15. cnt += board[i][j] == 'C';
  16. }
  17. if (cnt > 1){
  18. ans += cnt * (cnt - 1) / 2;
  19. }
  20. cnt = 0;
  21. for(int j = 0; j < n; ++j){
  22. cnt += board[j][i] == 'C';
  23. }
  24. if (cnt > 1){
  25. ans += cnt * (cnt - 1) / 2;
  26. }
  27. }
  28. cout << ans << '\n';
  29. }
  30.  
Success #stdin #stdout 0s 3424KB
stdin
4
CC..
C..C
.CC.
.CC.
stdout
9