Showing posts with label Strings. Show all posts
Showing posts with label Strings. Show all posts

Monday, May 1, 2017

URI Solution 1218 Getline Three - Shoes - Solution in C++ | Ad Hoc

URI Solution 1218 Getline Three - Shoes- Solution in C++ | Ad Hoc


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

Problem Name: URI Problem Getline Three - Shoes
Problem Number : URI - 1218
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1218 Code in CPP:


#include <cstdio>
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
int main()
{
 int n, size, number, count = 1;
    string s, num, tipo;
    size_t found;

    bool p = false;
    while(scanf("%i", &n) != EOF)
    {
     if(p) cout << endl;
     p = true;
     cin.ignore();
  getline(cin, s);
  int masc[45] = {0}; int femi[45] = {0};
  size = s.size();

  for (int i = 0; i < size; i += 5)
  {
   found = s.find(" ");
   num = s.substr(0, found);
   s = s.substr(found + 1);

   found = s.find(" ");
   tipo = s.substr(0, found);
   s = s.substr(found + 1);

   number = atoi(num.c_str());
   if(tipo == "M"){
    masc[number]++;
   }else{
    femi[number]++;
   }
  }

     cout << "Caso " << count << ":" << endl;
       cout << "Pares Iguais: " << (masc[n] + femi[n]) << endl;
       cout << "F: " << femi[n] << endl << "M: " << masc[n];
       count++;
      
       cout << endl;
    }

   return 0;
}
Read More

URI Solution - 1192 Paula's Mathematic Game - Solution in C++ | Ad Hoc, String

URI Solution - 1192 Paula's Mathematic Game - Solution in C++ | Ad Hoc, String


URI Online Judge Solution Paula's Mathematic Game | Ad Hoc


Problem Name: URI Problem Paula's Mathematic Game
Problem Number : URI - 1192
Online Judge : URI Online Judge Solution
Level: Ad Hoc
Solution Language : C plus plus

URI Solution 1192 Code in CPP:


#include <iostream>
using namespace std;

int main()
{
 int n, a_i, c_i, res;
 char a, b, c;

 cin >> n;

 for (int i = 0; i < n; ++i)
 {
  cin >> a >> b >> c;
  cin.ignore();

  a_i = a - '0';
  c_i = c - '0';

  if(a_i == c_i){
   res = a_i * c_i;
  }else{
   if(b >= 97 && b <= 122){
    res = a_i + c_i;
   }else{
    res = c_i - a_i;
   }
  }

  cout << res << endl;
 }

 return 0;
}
Read More

Sunday, November 20, 2016

URI Solution 1235 Inside Out in C++ language


URI Online Judge | 1235

Inside Out

By TopCoder*  USA
Timelimit: 1
Your printer has been infected by a virus and is printing gibberish. After staring at several printed pages for a while, you realize that it is printing every line inside-out. In other words, the left half of each line is being printed starting in the middle of the page and proceeding out toward the left margin. Similarly, the right half of each line is being printed starting at the right margin and proceeding in toward the middle of the page.

For example, the line:
THIS LINE IS GIBBERISH

is being printed as:
I ENIL SIHTHSIREBBIG S

In the same way, the line " MANGOS " is being printed as "NAM  SOG".Your task is to unscramble a String line from its printed form back into its original order. You can assume that line contains an even number of characters.

Input

The input contains many test cases. The first line of input contains an integer N that indicates the number of test cases. Follow N lines, each one with a string with the maximum of 100 uppercase letters ('A'-'Z') and spaces (' '). that must be unscrambled from its printed form back into its original order, like example above.

Output

Each line of input must produce a line of output, with the decoded message, like example above.
Sample InputSample Output
5
I ENIL SIHTHSIREBBIG S
LEVELKAYAK
H YPPAHSYADILO
ABCDEFGHIJKLMNOPQRSTUVWXYZ
VOD OWT SNEH HCNERF EGDIRTRAP A DNA SE
THIS LINE IS GIBBERISH
LEVELKAYAK
HAPPY HOLIDAYS
MLKJIHGFEDCBAZYXWVUTSRQPON
FRENCH HENS TWO DOVES AND A PARTRIDGE


URI Solution 1235 Inside Out in C++ language


#include <iostream>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int n, size;
    string s;
     
    cin >> n;
     
    for (int i = 0; i <= n; ++i) {
         
        getline(cin, s);
        if(i == 0)
            continue;
        size = s.length();       
        vector<char> v(size);
        for(int j = 0; j < size; ++j){v[j] = s[j];}
         
        reverse(v.begin(), v.begin() + (size/2));
        reverse(v.begin() + (size/2), v.begin() + size);
         
        for(int j = 0; j < size; ++j){cout << v[j];}
        cout << endl;
    }
     
    return 0;
}

Download the main Code From Dropbox (If any add occur please click skip button)
Read More

URI Solution 1262 Multiple Reading in C++ language

URI Online Judge | 1262

Multiple Reading


By TopCoder*  USA
Timelimit: 1
In many computer systems, multiple processes can read from the same resource during the same clock cycle, but only a single process can write to the resource during a clock cycle. Reads and writes cannot be mixed during the same clock cycle. Given a history of the reads and writes that occurred during a particular computation as a String trace, and an int procs representing the number of processes used by the computation, calculate the minimum duration of the computation in clock cycles. The trace represents each read as an 'R' and each write as a 'W'.
For example, if trace is "RWWRRR" and procs is 3, then the minimum number of clock cycles is 4: one for the first read, one each for the two writes, and one for the last group of reads.

Input


The input contains several test cases. Each test case is composed by two lines. The first line has a string made out of 1 to 50 characters, where each can be either 'R' or 'W'. The second line contains an integer (1 ≤ ≤ 10), which represents the number of processes as a direct indicator of how many read operations can be performed simultaneously. The input stream ends in EOF.

Output

For each test case determine and print the minimum number of clock cycles required to run the given trace. For further reference see the examples below.
Sample InputSample Output
RWWRRR
3
RWWRRRR
3
WWWWW
5
RRRRRRRRRR
4
RWRRWWRWRWRRRWWRRRRWRRWRRWRRRRRRRRRWRWRWRRRRWRRRRR
4
4
5
5
3
30


URI Solution 1262 Multiple Reading in C++ language


#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    string s;
    int p, size, ciclos, count;
    while(cin >> s >> p)
    {
        size = s.size();
        ciclos = 0; count = 0;
        for (int i = 0; i < size; ++i)
        {
            if(s[i] == 'R'){
                if(count == 0)
                    ciclos++;
                count++;
                if(count == p)
                    count = 0;
            }else{
                ciclos++;
                count = 0;
            }
        }
        printf("%i\n", ciclos);
    }
    return 0;
}

Download the main C++ Code from Dropbox (If any add occur please click skip button)


Tags:
URI solution 1262, URI onlien Judge Solution 1262, URI Multiple reading problem solution, URI problem solution, URI 1262 code, URI 1262 code in C++


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.