Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
a6
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
//Rextester.Program.Main is the entry point for your code. Don't change it. //Microsoft (R) Visual C# Compiler version 2.9.0.63208 (958f2354) using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { int accountleft=0; int accountright=0; int[] test = {1, 2, 5, 4, 4}; int f(int[] a) { int rightside = a.Length-1; int leftside = 0; int middle = a.Length/2; int left=a[0]; int right= a[rightside]; while(true) { if(leftside+1 == rightside && left != right ) { return 0; } else { if(left > right) { right+=a[rightside--]; accountright++; } else if (left < right) { left+=a[leftside++]; accountleft+=1; } else if(left == right) { if(accountleft==0) { accountleft++; } else if(accountright==0) { accountright++; } return 1; } else { return 0; } } } } int final = f(test); int accountlefts = accountleft; int accountrights = accountright; if(final==1) { String leftstring=""; String rightstring=""; while(accountlefts>0) { leftstring+="a["+accountlefts+"]+"; accountlefts--; } while(accountrights>0) { rightstring+="a["+accountrights+"]+"; accountrights--; } Console.WriteLine(accountleft+" Reason:"+leftstring); } else { } // Console.WriteLine(f(test)); Console.WriteLine(accountleft); Console.WriteLine(accountright); Console.WriteLine(test.Length); } } }
Show compiler warnings
[
+
]
Show input
Compilation time: 0,22 sec, absolute running time: 0,09 sec, cpu time: 0,11 sec, average memory usage: 15 Mb, average nr of threads: 3, absolute service time: 0,35 sec
edit mode
|
history
|
discussion
2 Reason:a[2]+a[1]+ 1 4 1 5