Created
November 9, 2015 20:40
-
-
Save nbarnold01/87596d2e364f2465f8fc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.m | |
// Sherlock and Array | |
// | |
// Created by Nathan Arnold on 11/9/15. | |
// Copyright © 2015 Nathan Arnold. All rights reserved. | |
// | |
#import <Foundation/Foundation.h> | |
void processTestCase() { | |
int numberOfElements = 0; | |
scanf("%d", &numberOfElements); | |
int elementArray[numberOfElements]; | |
long total = 0; | |
int subTotal = 0; | |
for (int i = 0; i<numberOfElements; i++) { | |
int item = 0; | |
scanf("%d", &item); | |
total += item; | |
elementArray[i] = item; | |
} | |
if (numberOfElements == 1) { | |
printf("YES\n"); | |
return; | |
} | |
for (int i = 1; i<numberOfElements; i++) { | |
subTotal += elementArray[i-1]; | |
if ((subTotal * 2) == total-elementArray[i]) { | |
printf("YES\n"); | |
return; | |
} | |
} | |
printf("NO\n"); | |
} | |
int main(int argc, const char * argv[]) { | |
// @autoreleasepool { | |
// insert code here... | |
// NSAutoreleasePool *pool = [[NSAutoreleasePool alloc]init]; | |
int numberOfTestCases = 0; | |
scanf("%d", &numberOfTestCases); | |
for (int i = 0; i < numberOfTestCases; i++){ | |
processTestCase(); | |
} | |
// } | |
// [pool drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment