7/31/2013

11636 - Hello World! - UVA

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.         int pastes  , N , lines;
  6.         int i = 0;
  7.         while(cin>>N)
  8.         {
  9.                 i++;
  10.                 lines = 1;
  11.                 pastes = 0;
  12.                 if(N<0)
  13.                         break;
  14.                 else if(== 1)
  15.                 {
  16.                         pastes = 0;
  17.                 }
  18.                 else
  19.                 {
  20.                         while(true)
  21.                         {
  22.                                 lines *=2;
  23.                                 if(lines >= N)
  24.                                 {
  25.                                         pastes++;
  26.                                         break;
  27.                                 }
  28.                                 else
  29.                                         pastes++;
  30.                         }
  31.                 }
  32.                 cout<<"Case "<<i<<": "<<pastes<<endl;
  33.         }
  34.         return 0;
  35. }


    You can find more of my solutions on Here

7/26/2013

11805 - Bafana Bafana - UVA

  1. #include<iostream>
  2. using namespace std;
  3. int main ()
  4. {
  5.         int testCases , N , K , P , position;
  6.        
  7.         cin>>testCases;
  8.        
  9.         for(int i = 0 ; i<testCases ; i++)
  10.         {
  11.                 cin>>N>>K>>P;
  12.                 position = K + P;
  13.                 while(position  > N)
  14.                 {
  15.                         position-=N;
  16.                 }
  17.                 cout<<"Case "<<i+1<<": "<<position<<endl;
  18.         }
  19.         return 0;
  20. }


    You can find more of my solutions on
     Here

7/25/2013

488 - Triangle Wave - UVA

  1. #include<iostream>
  2. using namespace std;
  3. void printWave(int amplitude)
  4. {
  5.         for(int i = 1; i <= amplitude; i++){
  6.                 for(int ii = 1; ii <= i; ii++){
  7.                         cout<<i;
  8.                 }
  9.                 cout<<endl;
  10.         }
  11.         for(int j = amplitude-1; j >= 1; j--){
  12.                 for(int jj = 1; jj<=; jj++){
  13.                         cout<<j;
  14.                 }
  15.                 cout<<endl;
  16.         }
  17. }
  18. int main ()
  19. {
  20.         int cases , amp , freq;
  21.         cin>>cases;
  22.         for(int i=0 ; i<cases ; i++){
  23.                 if(i>0) cout<<endl;
  24.                 cin>>amp>>freq;
  25.                 for(int j=0 ; j<freq; j++){
  26.                         if(j>0)cout<<endl;
  27.                         printWave(amp);
  28.                 }
  29.         }
  30.         return 0;
  31. }


    You can find more of my solutions on
     Here

7/11/2013

the 3n+1 Problem - 100 - UVA

  1. #include <iostream>
  2. #include<algorithm>
  3. using namespace std;
  4. int main ()
  5. {
  6.         int n , i , j;
  7.         while(cin>>i>>j)
  8.         {
  9.                 int tempi = i;
  10.                 int tempj = j;
  11.                 if(i>j)
  12.                         swap(i,j);
  13.                
  14.                 int maxCycle_Length = INT_MIN;
  15.                 int cycle_Length;
  16.                 while(i<=j)
  17.                 {
  18.                         n=i;
  19.                         cycle_Length = 1;
  20.                         while(n!=1){
  21.                                 if(n%2!=0)
  22.                                         n=(3*n)+1;
  23.                                 else
  24.                                         n = n/2;
  25.                                 cycle_Length++;
  26.                         }
  27.                         if(cycle_Length > maxCycle_Length)
  28.                                 maxCycle_Length = cycle_Length;
  29.                         i++;
  30.                 }
  31.                 cout<<tempi<<" "<<tempj<<" "<<maxCycle_Length<<endl;
  32.         }
  33.        
  34.         return 0;
  35. }


    You can find more of my solutions on
     Here

Summing digits - UVA 11332

  1. #include<iostream>
  2. using namespace std;
  3. long g(long x)
  4. {
  5.         if(x<10){return x;}
  6.         long sum = 0;
  7.         long temp = x;
  8.        
  9.         while(temp>0){
  10.                 sum+=temp%10;
  11.                 temp/=10;
  12.         }
  13.         return g(sum);
  14. }
  15. int main ()
  16. {
  17.         long num , result;
  18.         while(cin>>num)
  19.         {
  20.                 if(num==0)
  21.                         break;
  22.                 else{
  23.                         result = g(num);
  24.                         cout<<result<<endl;
  25.                 }
  26.         }
  27.         return 0;
  28. }

You can find more of my solutions on Here