Showing posts with label Mathematics. Show all posts
Showing posts with label Mathematics. Show all posts

Saturday, May 13, 2017

URI Solution 1213 Ones - Solution in C, C++

URI Solution 1213 Ones - Solution in C, C++


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

Problem Name: URI Problem 1213 Ones
Problem Number : URI Problem 1213 Ones Solution



 Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1213 Ones - Solution in C, C++

URI Solution 1213 Ones Code in C:

#include <stdio.h>
 
int main(int argc, char const *argv[])
{
 long long int n, l, c;
 
 while(scanf("%lli", &n) == 1){
  l = 1;c = 1;
 
  while(l % n != 0){
   l = (10 * l + 1) % n;
   c++;
  }
 
  printf("%lli\n", c);
 }
 
 return 0;
}


URI Solution 1213 Ones Code in C++:

#include <cstdio>
 
using namespace std;
 
int main(int argc, char const *argv[])
{
 long long int n, l, c;
 
 while(scanf("%lli", &n) == 1){
  l = 1;c = 1;
 
  while(l % n != 0){
   l = (10 * l + 1) % n;
   c++;
  }
 
  printf("%lli\n", c);
 }
 
 return 0;
}



Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1213 solution in C, URI 1213 solution in C++, URI Ones Solution, URI 1213 code in C, URI 1213 code in C++

Read More

URI Solution 1212 Primary Arithmetic - Solution in C, C++

URI Solution 1212 Primary Arithmetic - Solution in C, C++


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



 Problem Name: URI Problem 1212 Primary Arithmetic
Problem Number : URI Problem 1212 Primary Arithmetic Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C, C plus plus

URI Solution 1212 Primary Arithmetic - Solution in C, C++


URI 1212 solution in C language/ URI Primary arithmetic code in C:

#include <stdio.h>
#include <string.h>

long NumCarryAdd(long n1, long n2 )
{
    long a,b,c,t;
    c = 0;
    t = 0;
    while(1)
    {
        a=n1%10;
        b=n2%10;
        n1=n1/10;
        n2=n2/10;
        if((a+b+c)>=10)
        {
            t++;
            c=1;
        }
        else c = 0;
        if(n1==0 && n2==0)break;
    }
    return t;
}

int main()
{
    long x, y, carry;
    while(1)
    {
        scanf("%ld %ld", &x,&y);
        if(x == 0 && y == 0) break;
        carry = NumCarryAdd(x, y);
        if(carry == 0) printf("No carry operation.\n");
        else if(carry==1)printf("1 carry operation.\n");
        else printf("%ld carry operations.\n", carry);
    }
    return 0;
}


URI Solution 1212 Primary Arithmetic Code in CPP:

#include <iostream>
using namespace std;

int main(int argc, char const *argv[])
{
 long int a, b, _a, _b, c, carry, result;

 while (cin >> a >> b && (a || b))
 {
  carry = c = 0;
  
  while (a != 0 || b != 0)
  {
   _a = a % 10;
   a = a / 10;
   _b = b % 10;
   b = b / 10;

   result = _a + _b + c;
   if (result >= 10){
    c=1;
    carry += 1;
   }
   else
    c=0;
  }
  
  if (carry == 0){
   cout << "No carry operation." << endl;
  }
  else if (carry == 1){
   cout << carry << " carry operation." << endl;
  }
  else if (carry > 1){
   cout << carry << " carry operations." << endl;
  }
 }
 return 0;
}


Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list URI 1212 solution, URI Primary Arithmetic solution, URI 1212 Primary Arithmetic Solution, URI 1212 code in C, URI 1212 solution in C++

Read More

URI Solution 1199 Simple Base Conversion in C++

URI Solution 1199 Simple Base Conversion in C++


URI Online Judge Solution  1199 Simple Base Conversion| Mathematics
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1199

Problem Name: URI Problem 1199 Simple Base Conversion
Problem Number : URI Problem 1199 Simple Base Conversion Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C plus plus

URI Solution 1199 Simple Base Conversion in C++

URI Solution 1199 Simple Base Conversion Code in CPP:

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <sstream>
using namespace std;
 
int main()
{
    int n;
    string s;
    
    while(getline(cin, s))
    {
        n = atoi(s.c_str());
        
        if(n < 0){
            return 0;
        }
        
        if(s[1] == 'x'){
            istringstream(s) >> std::hex >> n;
            cout << std::dec << n << endl;
        }else{
            cout << "0x" << std::hex << uppercase << n << endl;
        }
    }
}


Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1199 Solution, URI 1199 solution in C, URI 1199 solution in C++


Read More

URI Solution 1198 Hashmat the Brave Warrior - Solution in C,C++,Java

URI Solution 1198 Hashmat the Brave Warrior - Solution in C,C++,Java


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

Problem Name: URI Problem 1198 Hashmat the Brave Warrior
Problem Number : URI Problem 1198 Hashmat the Brave Warrior Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C, C plus plus, Java

UVA Solution 1198 Hashmat the Brave Warrior - Solution in C,C++,Java


URI Solution 1198 Hashmat the Brave Warrior Code in C:

#include <stdio.h>

int main()
{
    long long x, y;

    while(scanf("%lld", &x) != EOF)
    {
        scanf("%lld", &y);
        if(x > y)
            printf("%lld\n", x-y);
        else
            printf("%lld\n", y-x);
    }

    return 0;
}



URI Solution 1198 Hashmat the Brave Warrior Code in CPP:

#include <iostream>

using namespace std;

int main()
{
 long long x, y;

 while(cin >> x >> y)
 {
  if(x < y){
   cout << y - x << endl;
  }else{
   cout << x - y << endl;
  }
 }

 return 0;
}


URI Solution 1198 Hashmat the Brave Warrior Code in Java:

import java.util.Scanner;

public class Main {

 public static void main(String[] args) {
  long x, y;
  Scanner input = new Scanner(System.in);
     while(input.hasNext())
     {
         x = input.nextLong();
         y = input.nextLong();
         if(x > y)
             System.out.println(x-y);
         else
             System.out.println(y-x);
     }

 }

}


Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1198 Solution, URI 1198 Solution in C, URI 1198 solution in java, URI 1198 solution in C++

Read More

URI Solution 1197 Back to High School Physics - Solutions in C, C++

URI Solution 1197 Back to High School Physics - Solutions in C, C++


URI Online Judge Solution  1197 Back to High School Physics | Data structures
URI Main Problem Link - 1197 Back to High School Physics https://www.urionlinejudge.com.br/judge/en/problems/view/1197

Problem Name: URI Problem 1197 Back to High School Physics
Problem Number : URI Problem 1197 Back to High School Physics Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C, C plus plus

URI Solution 1197 Back to High School Physics - Solutions in C, C++


URI Solution 1197 Back to High School Physics Code in C:

#include <stdio.h>

int main(){
    int v, t;

    while(scanf("%d", &v) != EOF){
        scanf("%d", &t);
        printf("%d\n", v*(2*t));
    }
    return 0;
}


URI Solution 1197 Back to High School Physics Code in CPP:

#include <iostream>
using namespace std;

int main()
{
 int v, t;

 while(cin >> v >> t)
 {
  cout << ((v * t) * 2) << endl;
 }

 return 0;
}




Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1197 solution in C, URI 1197 Code in C++, URI Back to high school solution

Read More

Thursday, May 11, 2017

URI Fast Prime Number Solution in C, C++ | URI 1221 Solution

URI Fast Prime Number Solution in C, C++ | URI 1221 Solution


URI Online Judge Solution Fast Prime Number  | Mathematics
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1221

Problem Name: URI Problem Fast Prime Number
Problem Number : URI Problem Fast Prime Number 1221 Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C, C plus plus

URI Fast Prime Number Solution in C, C++ | URI 1221 Solution

URI Solution 1221 Solution/Code in C:

#include <stdio.h>
#include <math.h>

int main(){
    int n, teste, i, j;
    long p;
    
    scanf("%d", &n);
    
    for(i = 0; i <n; i++){
            teste = 0;
            scanf("%ld", &p);
            
            if(p == 0){
                 printf("%s\n", "Not Prime");
                 continue;
            }
            
            if(p == 1){
                 printf("%s\n", "Not Prime");
                 continue;
            }
            
            if(p == 2){
                 printf("%s\n", "Prime");
                 continue;
            }
            
            for(j = 2; j < sqrt(p)+1; j++){
                    if(p%j == 0) teste++;
                    if(teste == 2) break;
            }
            
            if(teste >= 1) printf("%s\n", "Not Prime");
            else printf("%s\n", "Prime");
    }
    return 0;
}


URI Solution 1221 Solution/Code in C++:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
 int n, x;
 bool ver = false;

 cin >> n;

 for (int i = 0; i < n; ++i)
 {
  cin >> x;

  if(x == 2){
   cout << "Prime" << endl;
  }else{

   if(x % 2 == 0){
    cout << "Not Prime" << endl;
   }else{

    for (int j = 3; j < sqrt(x); j += 2)
    {
     if(x % j == 0)
      ver = true;
    }

    if(ver == true){
     cout << "Not Prime" << endl;  
    }else{
     cout << "Prime" << endl; 
    }
   }
  }

  ver = false;
 }

 return 0;
}


Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI Fast Prime Number Solution in C, C++ | URI 1221 Solution, URI 1221 Solution in c, URI 1221 code in C

Read More

URI 1193 Solution | URI Base Conversion Solution

URI 1193 Solution in C, C++ | URI Base Conversion Solution


URI Online Judge Solution  1193 Base Conversion | Mathematics
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1193

Problem Name: URI Problem 1193 Base Conversion
Problem Number : URI Problem 1193 Base Conversion  Solution
Online Judge : URI Online Judge Solution
Level: Data structures
Solution Language : C plus plus

URI 1193 Solution | URI Base Conversion Solution

URI Solution 1193 Base Conversion  Code in CPP:


#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <string>
using namespace std;

char digit_hex(int x)
{
    if(x >= 0 && x < 10) return (x + '0');
    else if (x < 16) return (x - 10 + 'a');
    else return '!';
}

string tobin(int x)
{
    string tmp;
    char c;
    while(x > 0)
    {
        c = x % 2 + '0';
        tmp = c + tmp;
        x /= 2;
    }
    return tmp;
}

string tohex(int x)
{
    string tmp;
    while(x > 0)
    {
        tmp = digit_hex(x % 16) + tmp;
        x /= 16;
    }
    return tmp;
}

void bin(char * c, string s)
{
    int x = strtol(c, 0, 2);
    cout << x << " dec" << endl;
    cout << tohex(x) << " hex" << endl;
}

void dec(char * c, string s)
{
    int x = strtol(c, 0, 10);
    cout << tohex(x) << " hex" << endl;
    cout << tobin(x) << " bin" << endl;
}

void hex(char * c, string s)
{
    int x = strtol(c, 0, 16);
    cout << x << " dec" << endl;
    cout << tobin(x) << " bin" << endl;
}

int main(int argc, char const *argv[])
{
    int n, count = 1;
    char c[50];
    string s;

    cin >> n;

    while(n--)
    {
        cin >> c >> s;
        cout << "Case " << count << ":" << endl;

        if(s == "bin"){
            bin(c, s);
        }else if(s == "dec"){
            dec(c, s);
        }else{
            hex(c, s);
        }

        count++;
        cout << endl; 
    }
    return 0;
}


Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1193 Solution, URI base conversion solution, URI 1193 code in C, URI 1193 Code in C++

Read More

URI 1170 Solution in C, C++ | URI Blobs Solution

URI 1170 Solution in C, C++ | URI Blobs Solution


URI Online Judge Solution Blobs | Mathematics
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1170

Problem Name: URI Problem 1170 Blobs
Problem Number : URI Problem 1170 Blobs Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C, C plus plus

URI 1170 Solution in C, C++ | URI Blobs Solution

URI Solution 1170 Blobs Code in C:

#include <stdio.h>

int main(){
    int n, dias, i;
    float x;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
            scanf("%f", &x);
            dias = 0;
            while(x > 1){
                    x /= 2;
                    dias++;
            }
            printf("%d dias\n", dias);
    }
    
    return 0;
}



URI Solution 1170 Blobs Code in C++:

#include <iostream>
using namespace std;

int main()
{
 int n, counter;
 float food;

 cin >> n;

 for (int i = 0; i < n; ++i)
 {
  cin >> food;
  counter = 0;

  while(food > 1)
  {
   counter++;
   food = food/2;
  }

  cout << counter << " dias" << endl;
 }

 return 0;
}



Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1170 code in C, URI 1170 code in C++, URI 1170 solution, URI BLob Soluton

Read More

URI 1169 Solution in C, C++ | URI Grains in a Chess Board Solution

URI 1169 Solution in C, C++ | URI Grains in a Chess Board Solution

URI Online Judge Solution  Grains in a Chess Board | Mathematics
URI Main Problem Link - https://www.urionlinejudge.com.br/judge/en/problems/view/1169

Problem Name: URI Problem 1169
Problem Number : URI Problem 1169 Solution
Online Judge : URI Online Judge Solution
Level: Mathematics
Solution Language : C, C plus plus

URI 1169 Solution in C, C++ | URI Grains in a Chess Board Solution

URI Solution 1169 Solution in C:

#include <stdio.h>
#include <math.h>

int main(){
    int n, x, i;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
            scanf("%d", &x);
            printf("%lld kg\n", (long long)(pow(2,x)/12000));
    }
    
    return 0;
}


URI Solution 1169 Solution in C++:

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

int main()
{
 int n, x;
 unsigned long long int q;
 
 cin >> n;
 
 for(int i = 0; i < n; ++i)
 {
  q = 1;
  cin >> x;
  
  if(x == 64){
   cout << "1537228672809129 kg" << endl;
  }else{
   for(int j = 0; j < x; ++j){q *= 2;}
   q = ((q/12)/1000);
   cout << fixed << setprecision(0) << q << " kg" << endl;
  }
 }
 
 return 0;
} 


Tags: Uri solve , Uri solution, URI oj Solve, URI Online Judge Solution list, URI 1169 solution, URI Grains in a Chess Board solution

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.