The program is compiled, but when you start and enter the first value, an error flies. What is the problem I can not understand. Code:
#include <iostream> #include <windows.h> #include <string> using namespace std; int main() { setlocale(0, ""); int n; string s; string temp; int numb; int mass[97]; for(int i = 0; i < 98; i++) { mass[i] = 0; } cin >> n; for(int k = 0; k < n; k++) { getline(cin, s); if(s.substr(s.length()-2, 1) == " ") { temp = s.substr(s.length()-1, 1); numb = atoi(temp.c_str()); mass[numb - 1] = mass[numb - 1] + 1; } else { temp = s.substr(s.length()-1, 1); numb = atoi(temp.c_str()); mass[numb - 1] = mass[numb - 1] + 1; } } for(int u = 0; u < n; u++) { if(mass[u] > 0) { cout << "School №" << u << ": " << mass[u] << endl; } } system("pause"); return 0; }