UVA498:

Polly the Polynomial

import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		while(sc.hasNextLine()){
			String c = sc.nextLine();
			String x = sc.nextLine();
			if(c.length() == 0 || x.length() == 0) break;

			// System.out.println(c.length());

			String[] coeffs = c.split(" ");
			// System.out.println(coeffs.length);
			String[] xx = x.split(" ");

			

			for(int i = 0; i < xx.length; i++){
				
				long nn = Long.parseLong(xx[i]);

				System.out.print(solve(coeffs, nn));

				if(i < xx.length -1){
					System.out.print(" ");
				}


			}
			System.out.println("");
		}

		System.exit(0);	

	}
	

	public static long solve(String[] a, long x){
		long num = 0;
		int c = 0;
		for(int i = a.length -1; i >= 0; i--){
			long nn = Long.parseLong(a[c]);
			num += nn * Math.pow(x, i); 
			c++;
		}	

		return num;
	}


}
[Back to Listing Page]

Home

Posts

Projects

Github

Contact

janzzen

Developed by Janzzen Ang powered by Vercel