Showing posts with label Data Structures. Show all posts
Showing posts with label Data Structures. Show all posts

Wednesday, May 10, 2017

URI Solution 1430 Jingle Composing | Data Structures

URI Solution 1430 Jingle Composing | Data Structures


URI Online Judge Solution  1430 Jingle Composing | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1430

Problem Name: URI Problem  1430 Jingle Composing
Problem Number : URI Problem 1430 Jingle Composing  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1430 Jingle Composing | Data Structures

URI Solution 1430 Jingle Composing  Code in CPP:


#include <cstdio>
#include <cstring>

using namespace std;

double calculate(char c)
{
 if(c == 'W') return 1.00;
 else if(c == 'H') return 0.5;
 else if(c == 'Q') return 0.25;
 else if(c == 'E') return 0.125;
 else if(c == 'S') return 0.0625;
 else if(c == 'T') return 0.03125;
 else return 0.015625;
}

int main(int argc, char const *argv[])
{
 int c, l, i;
 double s;
 char str[1000001];

 while(gets(str) && str[0] != '*')
 {
  s = c = 0;
  l = strlen(str);

  for (i = 0; i < l; ++i)
  {
   if(str[i] == '/'){
    if(s == 1.00)
     c++;
    s = 0;
   }else{
    s += calculate(str[i]);
   }
  }

  printf("%d\n", c);
 }

 return 0;
}

Tag: Uri solve 1430 Jingle Composing , Uri solution 1430 Jingle Composing , URI oj Solve 1430 Jingle Composing
Read More

URI Solution 1340 Can Guess the Data Structure! | Data Structures

URI Solution 1340 Can Guess the Data Structure! | Data Structures


URI Online Judge Solution  | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1340

Problem Name: URI Problem 1340 Can Guess the Data Structure!
Problem Number : URI Problem 1340 Can Guess the Data Structure!  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1340 Can Guess the Data Structure! | Data Structures


URI Solution 1340 Can Guess the Data Structure!  Code in CPP:


#include <cstdio>
#include <stack>
#include <queue>

using namespace std;

int main(int argc, char const *argv[])
{
 int n, x, y;
 bool _p, _q, _s;

 while(scanf("%d", &n) != EOF){
  priority_queue<int> p;
  queue<int> q;
  stack<int> s;
  _p = true, _q = true, _s = true; 

  for (int i = 0; i < n; ++i)
  {
   scanf("%d %d", &x, &y);
   if(x == 1){
    p.push(y);
    q.push(y); 
    s.push(y);
   }else{
    if(p.top() != y) _p = false;
    if(q.front() != y) _q = false;
    if(s.top() != y) _s = false;
    p.pop(); q.pop(); s.pop();
   }
  }

  if((_p && _q && _s) || (!_p && _q && _s) || (_p && !_q && _s) || (_p && _q && !_s)) printf("not sure\n");
  else if (_p && !_q && !_s) printf("priority queue\n");
  else if (!_p && _q && !_s) printf("queue\n");
  else if (!_p && !_q && _s) printf("stack\n");
  else printf("impossible\n");
 }

 return 0;
}

Tag: Uri solve 1340 Can Guess the Data Structure! , Uri solution 1340 Can Guess the Data Structure! , URI oj Solve 1340 Can Guess the Data Structure!
Read More

URI Solution 1303 Spurs Rocks | Data Structures

URI Solution 1303 Spurs Rocks | Data Structures


URI Online Judge Solution 1303 Spurs Rocks  | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1303

Problem Name: URI Problem 1303 Spurs Rocks
Problem Number : URI Problem 1303 Spurs Rocks Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1303 Spurs Rocks | Data Structures

URI Solution 1303 Spurs Rocks Code in CPP:



#include <cstdio>
#include <cstring>
#include <algorithm>

#define SC1(n) scanf("%d", &n)
#define SC4(a, b, c, d) scanf("%d %d %d %d", &a, &b, &c, &d)
#define CLEAR(x) memset(x, 0, sizeof(x))
#define FOR(i, n) for(int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;

typedef struct
{
 int id, p, pro, con;
}times;

times arr[101];

bool cmp(times a, times b)
{
 float avg, bvg;
    
    if(a.p == b.p){
     if(a.con == 0) avg = a.pro;   
  else avg = (float)a.pro/(float)a.con;
  if(b.con == 0) bvg = b.pro;
  else bvg = (float)b.pro/(float)b.con;
  
  if(avg == bvg){
   if(a.pro == b.pro){
       return a.id < b.id;
   }else{
       return a.pro < b.pro;
   }
  }else{
   return avg < bvg;
  }
    }else{
    return a.p < b.p;
    }
}

int main(int argc, char const *argv[])
{
 bool b = false;
 int n, x, y, z, w, h = 1, it;

 SC1(n);

 while(n)
 {
  if(b) printf("\n");
  b = true;

  CLEAR(arr);

  FOR(i, n)
     arr[i].id = (i + 1);

  it = (n * (n - 1)/2);

  FOR(i, it)
  {
     SC4(x, y, z, w);

     if(y > w){
    arr[x - 1].p += 2; arr[x - 1].pro += y; arr[x - 1].con += w;
    arr[z - 1].p += 1; arr[z - 1].pro += w; arr[z - 1].con += y;
     }else{
    arr[x - 1].p += 1; arr[x - 1].pro += y; arr[x - 1].con += w;
    arr[z - 1].p += 2; arr[z - 1].pro += w; arr[z - 1].con += y;
     }
  }

  stable_sort(arr, arr + n, cmp);
  reverse(arr, arr + n);

  printf("Instancia %d\n", h); h++;
  REP(i, 0, n)
  {
     printf("%d", arr[i].id);
     if(i != (n - 1)) printf(" ");
  }
  printf("\n");

  SC1(n);
 }

 return 0;
}

Tag: Uri solve 1303 Spurs Rocks  , Uri solution 1303 Spurs Rocks , URI oj Solve 1303 Spurs Rocks
Read More

URI Solution 1281 Going to the Market | Data Structures

URI Solution 1281 Going to the Market | Data Structures


URI Online Judge Solution  | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1281

Problem Name: URI Problem 1281 Going to the Market
Problem Number : URI Problem 1281 Going to the Market Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1281 Going to the Market | Data Structures

URI Solution 1281 Going to the Market Code in CPP:


#include <iostream>
#include <iomanip>
#include <cstring>
#include <map>
using namespace std;

int main()
{
 int n, m;
 float q, sumAll, tmp;
 string s, nome, qtd;
 size_t pos;

 cin >> n; cin.ignore();

 while(n--)
 {
  map<string, float> map;
  sumAll = 0;
  cin >> m; cin.ignore();
  
  while(m--)
  {
   getline(cin, s);
   size_t pos = s.find(' ');
   nome = s.substr(0, pos);
   qtd = s.substr(pos); 
   q = atof(qtd.c_str());
   map.insert(pair<string,float>(nome,q));
  }

  cin >> m; cin.ignore();

  while(m--)
  {
   getline(cin, s);
   size_t pos = s.find(' ');
   nome = s.substr(0, pos);
   qtd = s.substr(pos);
   q = atof(qtd.c_str());
   tmp = map[nome];
   sumAll += (q * tmp);
  }

  cout << "R$ " << fixed << setprecision(2) << sumAll << '\n';
 }

 return 0;
}

Tag: Uri solve 1281 Going to the Market , Uri solution 1281 Going to the Market , URI oj Solve 1281 Going to the Market
Read More

URI Solution 1261 Hay Points | Data Structures

URI Solution 1261 Hay Points | Data Structures


URI Online Judge Solution 1261 Hay Points  | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1261

Problem Name: URI Problem
Problem Number : URI Problem 1261 Hay Points  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1261 Hay Points | Data Structures

URI Solution 1261 Hay Points  Code in CPP:


#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <map>

#define SC1(a) scanf("%d", &a)
#define SC2(a, b) scanf("%d %d", &a, &b)
#define FOR(i, n) for(int i = 0; i < (n); ++i)
  
using namespace std;

typedef map<string, int> MI;
  
MI mapa;

int main(int argc, char const *argv[])
{
 int m, n, v, s;
 string w;
   
 while(SC2(m, n) == 2)
 {
  FOR(i, m)
  {
   cin >> w >> v;
   mapa[w] = v;
  }

  FOR(i, n)
  {
   s = 0;
   while(cin >> w && w.compare(".") != 0)
    s += mapa[w];

   printf("%d\n", s);
  }
 }
}

Tag: Uri solve 1261 Hay Points , Uri solution 1261 Hay Points , URI oj Solve 1261 Hay Points
Read More

URI Solution 1260 Hardwood Species | Data Structures

URI Solution 1260 Hardwood Species | Data Structures

URI Online Judge Solution 1260 Hardwood Species  | Data structures

Problem Name: URI Problem 1260 Hardwood Species 
Problem Number : URI Problem 1260 Hardwood Species Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1260 Hardwood Species | Data Structures


URI Solution 1260 Hardwood Species Code in CPP:


#include <iostream>
#include <iomanip>
#include <map>
#include <cstring>
  
using namespace std;
  
int main(){
    int n, t, count = 0;
    char c[31];
    double tot;
    map<string, int> map;
    std::map<string, int>::iterator it;
  
    cin >> n; cin.ignore();
    
    for (int i = 0; i < n; i++)
    {
     map.clear();
        tot = 0;
        if (count != 0){
         cout << endl;
        }else{
         gets(c); 
        }

        while (gets(c) && c[0] != '\0')
        {
            map[c]++;
            tot++;
        }
  
        for (it = map.begin(); it != map.end(); it++)
            cout << it->first << " " << fixed << setprecision(4) << (it->second*100*1.0)/tot << endl;
       
        count++;
    }

    return 0;
}

Tag: Uri solve 1260 Hardwood Species  , Uri solution 1260 Hardwood Species , URI oj Solve 1260 Hardwood Species 
Read More

URI Solution 1244 Sort by Length | Data Structures

URI Solution 1244 Sort by Length | Data Structures


URI Online Judge Solution  | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1244

Problem Name: URI Problem  1244 Sort by Length
Problem Number : URI Problem  1244 Sort by Length  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus


URI Solution  1244 Sort by Length  Code in CPP:


#include <iostream>
#include <cstring>
#include <algorithm>

using namespace std;

string arr[51];
int x;

bool compare(string a, string b) { return (a.length() <= b.length()); }

void split(string word)
{
 int size = word.length();
 int i = 0, x = 0, j = 0;
 string s;

 while(i <= size)
 {
  if(word[i] == ' ' || word[i] == '\0'){
   s = word.substr(j, i - j);
   arr[x] = s;
   j = i + 1;
   x++;
  }
  i++;
 }

 stable_sort(arr, arr + x, compare);
 reverse(arr, arr + x);

 for (i = 0; i < x; ++i)
 {
  cout << arr[i];
  if(i != (x - 1))
   cout << " ";
 }

 cout << endl;
}

int main(int argc, char const *argv[])
{
 int n, i;
 string word;

 cin >> n; cin.ignore();

 while(n--)
 {
  getline(cin, word);
  split(word);
 }

 return 0;
}

Tag: Uri solve 1244 Sort by Length  1244 Sort by Length  , Uri solution 1244 Sort by Length , URI 1244 Sort by Length  oj Solve
Read More

URI Solution 1215 Andy's First Dictionary | Data Structures

URI Solution 1215 Andy's First Dictionary | Data Structures


URI Online Judge Solution  1215 Andy's First Dictionary | Data structures

Problem Name: URI Problem 1215 Andy's First Dictionary 
Problem Number : URI Problem 1215 Andy's First Dictionary  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1215 Andy's First Dictionary | Data Structures

URI Solution 1215 Andy's First Dictionary Code in CPP:


#include <cstdio>
#include <vector>
#include <string>
#include <cstring>
#include <string.h>
#include <set>

using namespace std;

vector<string> v;
set<string> ss;

int main(int argc, char const *argv[])
{
 int l, i;
 char s[10005];
 char * pch;

 while(scanf("%s", s) == 1)
 {
  getchar();
  l = strlen(s);

  if(!l)
   continue;

  for (i = 0; i < l; ++i)
  {
   s[i] = tolower(s[i]);
   if(s[i] < 'a' || s[i] > 'z')
    s[i] = 32; 
  }

  pch = strtok(s, " ");

  while(pch != NULL)
  {
   if(strlen(pch) != 0)
    ss.insert(pch);
   pch = strtok(NULL, " ");
  }
 }

 set<string>::iterator it;
 for(it = ss.begin(); it != ss.end(); it++){
  printf("%s\n", (*it).c_str() );
 }

 return 0;
}

Tag: Uri solve 1215 Andy's First Dictionary , Uri solution 1215 Andy's First Dictionary , URI oj Solve 1215 Andy's First Dictionary 

Read More

URI Solution 1211 Economic Phonebook | Data Structures

URI Solution 1211 Economic Phonebook | Data Structures


URI Online Judge Solution  | Data structures
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1211

Problem Name: URI Problem 1211 Economic Phonebook
Problem Number : URI Problem 1211 Economic Phonebook Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1211 Economic Phonebook | Data Structures


URI Solution 1211 Economic PhonebookCode in CPP:


#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int i, j, sz;

bool compare(string a, string b)
{
 sz = a.length();

 for (i = 0; i < sz; ++i)
 {
  if(a[i] < b[i]) return 1;
  if(a[i] > b[i]) return 0;
 }

 return 1;
}

int main(int argc, char const *argv[])
{
 int n, l, c;
 char s[205];
 string base;

 while(scanf("%d", &n) == 1)
 {
  vector<string> v;
  c = 0;

  for (i = 0; i < n; ++i)
  {
   scanf("%s", s);
   v.push_back(s);
  }

  sort(v.begin(), v.end(), compare);
  base = v[0];
  l = base.length();

  for (i = 1; i < n; ++i)
  {
   for (j = 0; j < l; ++j)
   {
    if(base[j] == v[i][j]) c++;
    else break;
   }
   base = v[i];
  }

  printf("%d\n", c);
 }

 return 0;
}

Tag: Uri solve 1211 Economic Phonebook, Uri solution 1211 Economic Phonebook, URI 1211 Economic Phonebook oj Solve
Read More

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.