Wednesday, May 3, 2017

URI Solution 1547 Guess What - Solution in C, C++ | Ad Hoc

URI Solution 1547 Guess What - Solution in C, C++ | Ad Hoc


URI Online Judge Solution  | Ad Hoc
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1547

Problem Name: URI Problem 1547 Guess What Guess What
Problem Number : URI Problem 1547 Guess What  Solution
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1547 Guess What Code in CPP:


#include <iostream>
using namespace std;

int main()
{
 int n, q, s, x;
 int ctr = 0, ctr_f, tmp, res = 10000000;
 
 cin >> n;
 
 for(int i = 0; i < n; ++i)
 {
  cin >> q >> s;
  res = 10000000;
  ctr_f = 0;
  ctr = 0;
  
  for(int j = 0; j < q; ++j)
  {
   cin >> x;
   ctr++;
   
   tmp = s - x;
   if(tmp < 0)
    tmp = -tmp;
    
   if(tmp < res){
    res = tmp;
    ctr_f = ctr;
   }   
  }
  
  cout << ctr_f << endl;
  
 }
 
 return 0;
}

No comments:
Write comments

To know more about the problem, give us your valuable commment. We'll try to help you. Thanks

All rights reserved ©2016 -URI ONLINE JUDGE SOLUTION | Developed by Maniruzzaman Akash

© 2016 URI ONLINE JUDGE SOLUTION. Developed by Maniruzzaman Akash | Distributed By Gooyaabi Templates
Powered by Blogger.