UVA error output data
1 |
UVA error output data
1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
#include <iostream> using namespace std; int main() { int a,b; unsigned long long t; int cnt,c=0; while(cin>>a) { cin>>b; int tmp=min(1001,b); c++; cnt=0; for(int i=a;i<=tmp;i++) { for(int j=a;j<=tmp;j++) { t=(i*i*i)+(j*j*j); if(t/10>b || t/10<a) continue; if(t%10==3) cnt++; } } cout<<"Case "<<c<<": "<<cnt<<"\n"; } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
#include <iostream> using namespace std; #define M 301 int F[M]; int main() { unsigned long long n,m,s; int t,a,b; int a1,b1; int sum=0; F[1]=1; F[2]=1; F[3]=2; for(int i=4;i<M;i++) { F[i]=(F[i-1]+F[i-2])%100; } //cout<<F[296]<<" "<<F[297]<<" "<<F[298]<<" "<<F[299]<<" "<<F[300]<<" "<<F[301]<<" "<<F[302]<<"\n"; for(int i=1;i<M;i++) { sum+=F[i]; } //cout<<sum<<"\n"; cin>>t; while(t--) { cin>>n>>m; a=n%300; //a1=n/300; b=m%300 ; //b1=m/300; s=0; unsigned long long j,p; for(unsigned long long i=n;i<=m;i++) { if(i%300==0) { s+=F[300]; j=i; break; } s+=F[i%300]; if(i==m) j=m; } if(j==m) { cout<<s<<"\n"; continue; } p=m-j; s+=((p/300)*sum); j=j+(p/300)*300; for(unsigned long long i=j+1;i<=m;i++) { if(i%300==0) { s+=F[300]; j=i; break; } s+=F[i%300]; } cout<<s<<"\n"; } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
#include <iostream> using namespace std; int main() { int a,b,c; while(cin>>a) { cin>>b>>c; if(a==b &&b==c) { cout<<"*\n"; continue; } if(a!=b && a!=c) { cout<<"A\n"; continue; } if(b!=a && b!=c) { cout<<"B\n"; continue; } if(c!=b && a!=c) { cout<<"C\n"; continue; } } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
#include <iostream> #include <string> #include <string.h> #include <map> using namespace std; map<char,int> mp; int main() { string str; while(cin>>str) { if(str=="#") break; mp.clear(); for(int i=0;i<str.size();i++) { mp[str[i]]+=1; } if(mp.size()==1) { cout<<"\n"; continue; } int k=0; map<char,int> m; for(map<char,int>::iterator i=mp.begin();i!=mp.end();++i) { if((i->second)%2!=0) { k++; m[i->first]=1; } } int s=0; for(map<char,int>::iterator i=m.begin();i!=m.end();++i) { if(s==k-1) break; s++; cout<<i->first; } cout<<"\n"; } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include <iostream> using namespace std; int main() { int t; unsigned long long n; cin>>t; while(t--) { cin>>n; cout<<n/2<<"\n"; } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
#include <iostream> #include <string> #include <vector> #include <string.h> using namespace std; int prime[1000001]; vector <long long> vb; long long sumof(long long a) { long long l=0; while(a) { l+=a%10; a/=10; } return l; } int isPrime(long long n) { if(n<1000001) { if(prime[n]==0) return 1; else return 0; } for(int i=2;i*i<=n;i++) if(n%i==0) return 0; return 1; } int factorsum(long long n) { if(n<1000001) { if(prime[n]==0) return 1; } long long tmp=0; long long org=n; while(n) { int f=0; for(int i=0;i<vb.size();i++) { if(vb[i]>n) { f=0; break; } if(n%vb[i]==0) { tmp+=sumof(vb[i]); n/=vb[i]; f=1; break; } } if(f==0) { if(isPrime(n)==1 && n!=org) tmp+=sumof(n); break; } } //cout<<tmp<<" ds\n"; if(tmp==0) return 1; if(tmp==sumof(org)) return 0; return 1; } int main() { prime[0]=1; prime[1]=1; for(int i=4;i<1000001;i+=2) { prime[i]=1; } for(int i=3;i*i<1000001;i+=2) { if(prime[i]==0) { for(int j=i+i;j<1000001;j+=i) prime[j]=1; } } //vb.clear(); vb.push_back(2); for(int i=3;i<1000001;i+=2) { if(prime[i]==0) vb.push_back(i); } int t; long long n; //cout<<vb[vb.size()-1]<<"\n"; //cout<<isPrime(1000000007)<<"\n"; //cout<<factorsum(1000000007)<<"\n"; //cout<<prime[45495]<<"\n"; //cout<<sumof(456502); cin>>t; while(t--) { cin>>n; n++; while(factorsum(n)) { n++; } cout<<n<<"\n"; } //getchar(); return 0; } |
Tree Recursion
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include <iostream> #include <stdio.h> #include <string.h> #include <string> using namespace std; // A utility function to search x in arr[] of size n int search(char arr[], char x, int n) { for (int i = 0; i < n; i++) if (arr[i] == x) return i; return -1; } // Prints postorder traversal from given inorder and preorder traversals void printPostOrder(char in[], char pre[], int n) { // The first element in pre[] is always root, search it // in in[] to find left and right subtrees int root = search(in, pre[0], n); // If left subtree is not empty, print left subtree if (root != 0) printPostOrder(in,pre+1,root); // If right subtree is not empty, print right subtree if (root != n-1) printPostOrder(in+root+1,pre+root+1,n-root-1); // Print root cout << pre[0]; } // Driver program to test above functions int main() { char in[28]; char pre[28]; while(scanf("%s %s",pre,in) == 2) { int n = strlen(in); //printf("%d\n",search(in, pre[0], n)); //cout<<n<<"\n"; //cout << "Postorder traversal " << endl; printPostOrder(in, pre, n); cout<<"\n"; } return 0; } |
Its a fibonicci series solution. I dont know why….But found that it shows the similiarity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#include <iostream> #include <vector> using namespace std; int fib[2000][5000]; vector<int> vb[2001]; int main() { fib[0][0]=1; fib[1][0]=2; fib[2][0]=3; int c=0; for(int i=3;i<2000;i++) { for(int j=0;j<5000;j++) { int t=fib[i-1][j]+fib[i-2][j]+c; fib[i][j]=t%10; c=t/10; } } //cout<<fib[3][0]; vb[0].push_back(1); vb[1].push_back(2); vb[2].push_back(3); for(int i=3;i<2000;i++) { int f=0; for(int j=4999;j>=0;j--) { if(f) { vb[i].push_back(fib[i][j]); continue; } if(fib[i][j]) { vb[i].push_back(fib[i][j]); f=1; } } } int n; while(cin>>n) { for(int i=0;i<vb[n].size();i++) cout<<vb[n][i]; cout<<"\n"; } return 0; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
#include <iostream> #include <string> #include <vector> #include <string.h> using namespace std; int main() { int n; string str; cin>>n; while(n--) { cin>>str; if(str.size()==5) { cout<<"3"<<"\n"; continue; } int cnt=0; if(str[0]=='o'|| str[0]=='n' || str[0]=='e') { cnt++; } if((str[1]=='o'|| str[1]=='n' || str[1]=='e') && str[1]!=str[0]) { cnt++; } if((str[2]=='o'|| str[2]=='n' || str[2]=='e') && str[1]!=str[2] && str[2]!=str[0]) { cnt++; } if(cnt>=2) { cout<<"1"<<"\n"; continue; } cnt=0; if(str[0]=='t'|| str[0]=='w' || str[0]=='o') { cnt++; } if((str[1]=='t'|| str[1]=='w' || str[1]=='o') && str[1]!=str[0]) { cnt++; } if((str[2]=='t'|| str[2]=='w' || str[2]=='o')&& str[1]!=str[2] && str[2]!=str[0]) { cnt++; } if(cnt>=2) { cout<<"2"<<"\n"; continue; } } return 0; } |