fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <istream>
  5.  
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. int n, k, counting = 0;
  11. cin >> n >>k;
  12. char trash;
  13. cin.get(trash);
  14. vector<string> cards;
  15. string theline, name;
  16. cin >> theline;
  17. cout << "the line : " << theline << "\n";
  18. for (int i = 0; i < n; i++){
  19. name = theline[i];
  20. cards.push_back(name);
  21. }
  22. for (int i = 0; i < n; i++){
  23. if (cards[i] == cards[k-1]){
  24. counting++;
  25. }
  26. }
  27. int tmp = 0;
  28. cout << "counting : " << counting << std::endl;
  29. if (cards.size() != k){
  30. tmp = k - counting;
  31. }
  32. cout << "tmp : " << tmp << std::endl;
  33. cout << "counting : " << counting << std::endl;
  34. counting *= k;
  35. cout << "counting : " << counting << std::endl;
  36. counting += tmp;
  37. cout << "counting : " << counting << std::endl;
  38. cout << counting;
  39. return 0;
  40. }
  41.  
Success #stdin #stdout 0s 3484KB
stdin
6 4
YJSNPI
stdout
the line : YJSNPI
counting : 1
tmp : 3
counting : 1
counting : 4
counting : 7
7