First, solve the problem. Then, write the code. ” - John Johnson

It's not at all important to get it right the first time. It's vitally important to get it right the last time. ” - Andrew Hunt and David Thomas

Sunday, July 20, 2014

An Interesting Game.

Author : Jisan
Programming language : Java 
Difficulty : Easy
Status : Accepted
Problem number : UVA-12751
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=4604

Code:

import java.util.*;
public class Uva_12751 {

public static void main(String[] args) {
Scanner in=new Scanner(System.in);
int a=in.nextInt();
int s=0;

for(int cases=1;cases<=a;cases++){
int b=in.nextInt();
int k=in.nextInt();
int x=in.nextInt();

int rem=0;
for(int c=0;c<k;c++){
rem=rem+x;
x++;
}
s=(b*(b+1))/2;
System.out.println("Case "+cases+": "+(s-rem));
}

}

}


No comments:

Post a Comment