How to optimize this code!?

You need to reduce code or the compiler (in which the task is checked)
swears that spent a lot of time (over 1 second)

the task is completed, already three ways, but the time is still not satisfied..

TASK: 5ca09e0984a7c808379768.pngCODE:
#include <stdio.h>
#define true_1 (1)
#define false_1 (0)
int main()
{
 int input[100];
 int i = 0;
 int c = 0;
 int temp = 0;
 int counter = 0;
 while (c != 10)
{
 c = getchar();
 if (c != 10)
{
 input[i] = c; 
i++;
}
}
 temp = input[1];
 for (int d = 2; d < i; d++)
{
 if ((temp - input[d]) == -2)
{
counter++;
}
 temp = input[d];
}
 printf("%d", counter);
}


THANKS IN ADVANCE
March 19th 20 at 09:23
4 answers
March 19th 20 at 09:25
Solution
Read from a big block into an array, then process the array. And so to the end of the file.
Buffered input in the standard library does the same thing, but if it is to implement in code will still be able to save a little. If you allocate the array large enough, you may be able to process the file in one read operation.
March 19th 20 at 09:27
In the first while loop the if condition is superfluous, this is the first that encounter.
Thanks, I added the last, after 4 attempts to download the task - russell_Bartoletti35 commented on March 19th 20 at 09:30
@russell_Bartoletti35, you can remove the variable temp and replace all its references to input[1]. - stanley.Paucek80 commented on March 19th 20 at 09:33
@stanley.Paucek80, will Try, thanks - russell_Bartoletti35 commented on March 19th 20 at 09:36
March 19th 20 at 09:29
int count = 0;
int possible = 0;
int loop = 1;
while (loop) {
 switch (getchar()) {
 case '<':
 possible = 1;
break;
 case '>':
 if (possible) {
count++;
}
 possible = 0;
break;
 case '*':
 possible = 0;
break;
default:
 loop = 0;
break;
}
}
Yes, but unfortunately I can not use switch, case) - russell_Bartoletti35 commented on March 19th 20 at 09:32
@russell_Bartoletti35, the same can be recorded through if. - Camille_Lockman commented on March 19th 20 at 09:35
@Camille_Lockman, it's not working XD - russell_Bartoletti35 commented on March 19th 20 at 09:38
@russell_Bartoletti35,
int count = 0;
int possible = 0;
char ch;
while (1) {
 ch = getchar();
 if ('<' == ch) {
 possible = 1;
 } else if ('>' == ch) {
 if (possible) {
count++;
}
 possible = 0;
 } else if ('*' == ch) {
 possible = 0;
 } else {
break;
}
}
- Camille_Lockman commented on March 19th 20 at 09:41
March 19th 20 at 09:31
Why all these long arrays? just looking for couples <>:

int count = 0;
 for(char last = 0, c = getchar(); c != '\n'; c = getchar())
{
 if (last == '<' && c == '>') ++count;
 last = c;
}
 printf("%d\n",count);
would love to, but the input I have to use the array(( - russell_Bartoletti35 commented on March 19th 20 at 09:34

Find more questions by tags C