- #include<iostream>
- using namespace std;
- int main ()
- {
- int pastes , N , lines;
- int i = 0;
- while(cin>>N)
- {
- i++;
- lines = 1;
- pastes = 0;
- if(N<0)
- break;
- else if(N == 1)
- {
- pastes = 0;
- }
- else
- {
- while(true)
- {
- lines *=2;
- if(lines >= N)
- {
- pastes++;
- break;
- }
- else
- pastes++;
- }
- }
- cout<<"Case "<<i<<": "<<pastes<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
7/31/2013
11636 - Hello World! - UVA
7/26/2013
11805 - Bafana Bafana - UVA
- #include<iostream>
- using namespace std;
- int main ()
- {
- int testCases , N , K , P , position;
- cin>>testCases;
- for(int i = 0 ; i<testCases ; i++)
- {
- cin>>N>>K>>P;
- position = K + P;
- while(position > N)
- {
- position-=N;
- }
- cout<<"Case "<<i+1<<": "<<position<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
7/25/2013
488 - Triangle Wave - UVA
- #include<iostream>
- using namespace std;
- void printWave(int amplitude)
- {
- for(int i = 1; i <= amplitude; i++){
- for(int ii = 1; ii <= i; ii++){
- cout<<i;
- }
- cout<<endl;
- }
- for(int j = amplitude-1; j >= 1; j--){
- for(int jj = 1; jj<=j ; jj++){
- cout<<j;
- }
- cout<<endl;
- }
- }
- int main ()
- {
- int cases , amp , freq;
- cin>>cases;
- for(int i=0 ; i<cases ; i++){
- if(i>0) cout<<endl;
- cin>>amp>>freq;
- for(int j=0 ; j<freq; j++){
- if(j>0)cout<<endl;
- printWave(amp);
- }
- }
- return 0;
- }
You can find more of my solutions on Here
7/11/2013
the 3n+1 Problem - 100 - UVA
- #include <iostream>
- #include<algorithm>
- using namespace std;
- int main ()
- {
- int n , i , j;
- while(cin>>i>>j)
- {
- int tempi = i;
- int tempj = j;
- if(i>j)
- swap(i,j);
- int maxCycle_Length = INT_MIN;
- int cycle_Length;
- while(i<=j)
- {
- n=i;
- cycle_Length = 1;
- while(n!=1){
- if(n%2!=0)
- n=(3*n)+1;
- else
- n = n/2;
- cycle_Length++;
- }
- if(cycle_Length > maxCycle_Length)
- maxCycle_Length = cycle_Length;
- i++;
- }
- cout<<tempi<<" "<<tempj<<" "<<maxCycle_Length<<endl;
- }
- return 0;
- }
You can find more of my solutions on Here
Summing digits - UVA 11332
- #include<iostream>
- using namespace std;
- long g(long x)
- {
- if(x<10){return x;}
- long sum = 0;
- long temp = x;
- while(temp>0){
- sum+=temp%10;
- temp/=10;
- }
- return g(sum);
- }
- int main ()
- {
- long num , result;
- while(cin>>num)
- {
- if(num==0)
- break;
- else{
- result = g(num);
- cout<<result<<endl;
- }
- }
- return 0;
- }
You can find more of my solutions on Here
Subscribe to:
Comments (Atom)