+ 1
timelimit exeeded?
i am trying to make a program where youre able to input 20 names and then output some of them with numbers but i get an error with: timelimit exeeded. #include <iostream> using namespace std; int main() { int selected; string arr[20]; for(int i = 0; i < 20; i++) std::cin >> arr[i]; cin >> selected; cout << "These people didnt make there homework:" << endl << arr[selected] << endl; return 0 }
6 Respostas
+ 1
maybe when you run it you write only 1 input,
but if you write the first string then press enter, write the second string then press enter (for 20 times) and write the number (because the last input is an integer) it works.
Example:
(run the program)
(1st string) John
(2nd string) James
.
.
(20th string) Bart
(the variable selected) 5
then submit
+ 1
it worked but now it gives a weird error about the printf code. i don't know the scanf so i dont know what it means
+ 1
thank you leo! but what does timelimit mean? it could help in future problems.
+ 1
because you don't write the remain of strings so the for loop wait the next input but if you write this code in your PC and run it you will not have this problem
0
It may help you using "scanf" instead of "cin" and including "cstdio" as a header file.
0
leave the code that you wrote (change std::cin with cin) and try that I sayed