View Code of Problem 1

#include <stdio.h>
int main() {
    int a = 0;
    int b = 0;
	int minusA = false;
	int minusB = false;
	char c;
	char target = 'a';
	while((c = getchar()) != EOF){
		if (c == '\n') {
			if (minusA) {
				a = -a;
			}
			if (minusB) {
				b = -b;
			}
			printf("%d\n",a + b);
			a = 0;
			b = 0;
			minusA = false;
			minusB = false;
			target = 'a';
		} else {
			if (c == ' ') {
				target = 'b';
			} else if (c == '-') {
				if (target == 'a') {
					minusA = true;
				} else {
					minusB = true;
				}
			} else if (target == 'a'){
				a = a * 10 + (c - '0');
			} else {
			    b = b * 10 + (c - '0');
			}
		}
	}
	return 0;
}
/*
Main.c: In function 'main':
Main.c:5:15: error: 'false' undeclared (first use in this function)
  int minusA = false;
               ^
Main.c:5:15: note: each undeclared identifier is reported only once for each function it appears in
Main.c:28:15: error: 'true' undeclared (first use in this function)
      minusA = true;
               ^
*/

Double click to view unformatted code.


Back to problem 1