Sunday, 18 November 2018

uva problem 11364 Parking solution

  1. #include<bits/stdc++.h>
  2. #include<vector>
  3. #include<algorithm>
  4. using namespace std;
  5. int main()
  6. {
  7.     int num,t,n;
  8.     vector<int> ss;
  9.     cin>>t;
  10.     while(t--){
  11.     cin>>num;
  12.     for(int i=1;i<=num;i++){
  13.         cin>>n;
  14.         ss.push_back(n);
  15.     }
  16.     sort(ss.begin(), ss.end());
  17.     int sum;
  18.     sum=ss[ss.size()-1]- ss[0];
  19.     cout<<sum*2<<endl;
  20.     ss.clear();
  21.     }
  22.     return 0;
  23. }

uva problem 11192 Group Reverse solution

  1. #include<bits/stdc++.h>
  2. #include<string>
  3. using namespace std;
  4. int main()
  5. {
  6.     int num,ln;
  7.     string str;
  8.     char st[1001],r[1001];
  9.     while(cin>>num && num!=0){
  10.         cin>>str;
  11.         ln=str.length();
  12.         int div,k=0;;
  13.     div=ln/num;
  14.     int d=0;
  15.     for(int i=0;i<str.length();i++){
  16.                if(d==div){
  17.                 for(int j=d-1;j>=0;j--) st[k++]=r[j];
  18.                 d=0;
  19.                 r[d++]=str[i];
  20.                }
  21.                else {
  22.                 r[d++]=str[i];
  23.                }
  24.     }
  25.     for(int j=d-1;j>=0;j--) st[k++]=r[j];
  26.  
  27.    for(int i=0;i<k;i++) cout<<st[i];
  28.    cout<<endl;
  29.  
  30.  
  31.     }
  32.     return 0;
  33. }

uva problem 11152 Colourful Flowers solution

  1. #include<bits/stdc++.h>
  2. #include<cmath>
  3. using namespace std;
  4. int main()
  5. {
  6.     double a,b,c,s,r,red,rr,v,R;
  7.     while(cin>>a>>b>>c){
  8.         s=a+b+c;
  9.         s=s/2;
  10.         rr=sqrt(s*(s-a)*(s-b)*(s-c));
  11.         r=rr/s;
  12.         red=acos(-1);
  13.         red=red*r*r;
  14.         v=rr-red;
  15.         R=(a*b*c)/(4*rr);
  16.         R=acos(-1)*R*R;
  17.         R=R-rr;
  18.         printf("%0.4lf %0.4lf %0.4lf\n",R,v,red);
  19.     }
  20.     return 0;
  21. }

uva problem 11057 Exact Sum solution

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int arr[10005];
  6.    int n,m,mi,d;
  7.    while(cin>>n){
  8.         mi=1000001;
  9.         int x,y;
  10.    for(int i=0;i<n;i++){
  11.     cin>>arr[i];
  12.    }
  13.    cin>>m;
  14.     for(int i=0;i<n-1;i++){
  15.         for(int j=i+1;j<n;j++){
  16.             if((arr[i]+arr[j])==m){
  17.                     d=(arr[i]>arr[j]?arr[i]-arr[j]:arr[j]-arr[i]);
  18.             if(d<mi){
  19.                 mi=d;
  20.                 x=arr[i];
  21.                 y=arr[j];
  22.             }
  23.             }
  24.         }
  25.     }
  26.     if(x>y){
  27.         int t;
  28.         t=x;
  29.         x=y;
  30.         y=t;
  31.     }
  32.     cout<<"Peter should buy books whose prices are "<<x<<" and "<<y<<".\n\n";
  33.    }
  34.  
  35.     return 0;
  36. }

uva problem 10945 Mother bear solution

  1. #include<bits/stdc++.h>
  2. #include<string.h>
  3. #include<string>
  4. using namespace std;
  5. int main()
  6. {
  7.     char str[100000],r[100000],cas[100000];
  8.  
  9.     while(gets(str)){
  10.             int j=0;
  11.             if(strcmp(str,"DONE")==0) break;
  12.             for(int i=0;i<strlen(str);i++){
  13.                 if(isalpha(str[i])) r[j++]= str[i];
  14.             }
  15.      for(int i=0;i<j;i++) {
  16.         if(r[i]>='a' && r[i]<='z') r[i]=r[i]-32;
  17.      }
  18.       for(int i=0;i<j;i++)
  19.        {
  20.         cas[j-1-i]=r[i];
  21.        }
  22.        int c=0;
  23.        for(int i=0;i<j;i++){
  24.         if(cas[i]==r[i]) c++;
  25.        }
  26.        if(c==j) cout<<"You won't be eaten!\n";
  27.        else cout<<"Uh oh..\n";
  28.     }
  29.     return 0;
  30. }

variable declaration of c program

#include <stdbool.h> #include<bits/stdc++.h> #include <stdio.h> #include <string.h> #include <std...