diff options
| author | Aditya Naik | 2018-05-09 21:44:24 -0400 |
|---|---|---|
| committer | Aditya Naik | 2018-05-09 21:44:24 -0400 |
| commit | c6e35f76dfe3eefddd64ca64dda3ab1449048464 (patch) | |
| tree | 21c7ccca9f1fc8a4a575508a5ba109da513d4c59 | |
initial
| -rwxr-xr-x | amazing/amazing | bin | 0 -> 102112 bytes | |||
| -rw-r--r-- | amazing/amazing.cpp | 163 | ||||
| -rw-r--r-- | amazing/amazing.in | 108 | ||||
| -rw-r--r-- | amazing/amazing.py | 4 | ||||
| -rw-r--r-- | amazing/backup | 126 | ||||
| -rwxr-xr-x | average/average | bin | 0 -> 35696 bytes | |||
| -rw-r--r-- | average/average.cpp | 119 | ||||
| -rw-r--r-- | average/average.in | 8 | ||||
| -rw-r--r-- | lonesome/lonesome.cpp | 38 | ||||
| -rwxr-xr-x | rfp/rfp | bin | 0 -> 63128 bytes | |||
| -rw-r--r-- | rfp/rfp.cpp | 37 | ||||
| -rw-r--r-- | rfp/rfp.in | 32 |
12 files changed, 635 insertions, 0 deletions
diff --git a/amazing/amazing b/amazing/amazing Binary files differnew file mode 100755 index 0000000..9a65934 --- /dev/null +++ b/amazing/amazing diff --git a/amazing/amazing.cpp b/amazing/amazing.cpp new file mode 100644 index 0000000..e9bc8d6 --- /dev/null +++ b/amazing/amazing.cpp @@ -0,0 +1,163 @@ +#include <iostream> +#include <string> +#include <vector> +#include <iomanip> +using namespace std; +/* +rows +j 0 1 2 3 4 +i +0 <0 1 0 1 0> +1 <0 1 0 1 0> +2 <0 0 0 0 0> + */ +// struct sq{ +// sq* N; +// sq* S; +// sq* E; +// sq* W; +// int count; +// }; + + +char turn_left(char); +char turn_right(char); + +int main(){ + int b, w, count[100][100]={0}; + vector<char> sq[100]; + string s; + + cin>>b>>w; + while(b>0){ + int count[100][100]={0}; + vector<char> sq[100]; + string s; + + for(int i=0;i<b;i++){ + cin>>s; + for(int j=0;j<w;j++) + sq[i].push_back(s[j]); + } + + int j = 0, i=b-1; + int wallj = 0, walli=b; + char dir='E'; + bool returned=false; + + while(!returned){ + if((walli<b && walli>=0) && (wallj>=0 && wallj<w)) + if(sq[walli][wallj]=='0'){ + if(dir=='S'){ + walli--; + wallj++; + } + else if(dir=='W'){ + walli++; + wallj++; + } + else if(dir=='N'){ + walli++; + wallj--; + } + else if(dir=='E'){ + walli--; + wallj--; + } + dir = turn_right(dir); + } + + if(dir=='E'){ + if(j+1<w && sq[i][j+1]=='0'){ + j++; + wallj++; + count[i][j]++; + } + else{ + dir = turn_left(dir); + walli--; + wallj++; + } + } + else if(dir=='N'){ + if(i-1>=0 && sq[i-1][j]=='0'){ + i--; + walli--; + count[i][j]++; + } + else{ + dir = turn_left(dir); + walli--; + wallj--; + } + } + else if(dir=='W'){ + if(j-1>=0 && sq[i][j-1]=='0'){ + j--; + wallj--; + count[i][j]++; + } + else{ + dir = turn_left(dir); + walli++; + wallj--; + } + } + else if(dir=='S'){ + if(i+1<b && sq[i+1][j]=='0'){ + i++; + walli++; + count[i][j]++; + } + else{ + dir = turn_left(dir); + walli++; + wallj++; + } + } + + if(i==b-1 && j==0) + returned = true; + } + + int visited[5]={0}; + for(int i=0; i<b; i++){ + for(int j=0; j<w; j++){ + if(count[i][j]>4) + continue; + else if(sq[i][j]=='0') + visited[count[i][j]]++; + } + } + for(int k=0; k<5; k++) + cout<<right<<setw(3)<<visited[k]; + cout<<endl; + cin>>b>>w; + } +} + +char turn_left(char dir){ + char new_dir; + if(dir=='E') + new_dir = 'N'; + else if(dir=='N') + new_dir = 'W'; + else if(dir=='W') + new_dir = 'S'; + else if(dir == 'S') + new_dir = 'E'; + return new_dir; +} + +char turn_right(char dir){ + char new_dir; + if(dir=='E') + new_dir = 'S'; + else if(dir=='N') + new_dir = 'E'; + else if(dir=='W') + new_dir = 'N'; + else if(dir == 'S') + new_dir = 'W'; + return new_dir; +} diff --git a/amazing/amazing.in b/amazing/amazing.in new file mode 100644 index 0000000..52d676a --- /dev/null +++ b/amazing/amazing.in @@ -0,0 +1,108 @@ +11 10 +0010000100 +0100000001 +0100000100 +1010000000 +0001000000 +0000000000 +0011011000 +0010000001 +0101000000 +0000000011 +0010100101 +2 24 +001100010000000000000000 +000010101100101000001010 +12 28 +1000100000101000010000100100 +0001001000000001001001000010 +0000000000000100000001000100 +1000011100000000000100000001 +0001000100010010000011000010 +0000100000000000000001101000 +0000000000000000001010000000 +0100000000010010000000100000 +0001000000110000101010100100 +0000110000001101000000001000 +0000100000111001000000100000 +0001101100000010111010111100 +29 6 +000000 +111000 +110011 +000000 +110011 +000000 +000100 +101000 +000000 +000100 +100001 +000100 +010000 +001010 +000000 +001010 +100110 +001100 +110000 +001000 +000001 +000100 +100000 +000000 +001000 +001100 +000000 +010000 +000000 +8 27 +110100000100000100010000000 +000000000001010101010000001 +000110110000010000010000001 +000100100001000001000000000 +000000001000111101000010010 +001000100100110001000010100 +001000000011000000000101000 +000000000000000100000001000 +11 24 +010000100000000001001001 +000000000101001000000110 +010000000010000000000101 +010010001100000001000001 +000100000000000000100100 +000100011010100000101000 +001001000100000000100101 +001001110000000000000001 +110011001000100001000000 +000000001000100100110100 +000010100000000000011001 +8 29 +01000110000000000000010000000 +11010101000000000011000000000 +00000000100100100000000000000 +11000100011000000000001010000 +00000001111000100000000000000 +00000011000000000000100100100 +00011100000111001100100000000 +00110000001000100000100011100 +5 3 +001 +010 +100 +000 +000 +9 3 +011 +000 +011 +000 +000 +000 +000 +000 +000 +2 11 +00000000001 +00111001000 +0 0
\ No newline at end of file diff --git a/amazing/amazing.py b/amazing/amazing.py new file mode 100644 index 0000000..6df6194 --- /dev/null +++ b/amazing/amazing.py @@ -0,0 +1,4 @@ + + +class square: + diff --git a/amazing/backup b/amazing/backup new file mode 100644 index 0000000..2ffcb12 --- /dev/null +++ b/amazing/backup @@ -0,0 +1,126 @@ +#include <iostream> +#include <string> +#include <vector> +using namespace std; +/* +rows +j 0 1 2 3 4 +i +0 <0 1 0 1 0> +1 <0 1 0 1 0> +2 <0 0 0 0 0> + */ +// struct sq{ +// sq* N; +// sq* S; +// sq* E; +// sq* W; +// int count; +// }; + + +char turn_left(char); +char turn_right(char); + +int main(){ + int b, w, count[100][100]={0}; + vector<char> sq[100]; + string s; + + cin>>b>>w; + while(b>0){ + for(int i=0;i<b;i++){ + cin>>s; + for(int j=0;j<w;j++) + sq[i]; + } + + int j = 0, i=b-1; + int wallj = 0, walli=b; + char dir='E'; + bool returned=false; + + while(!returned){ + count[i][j]++; + + if(sq[walli][wallj]==0) + dir = turn_right(dir); + + if(dir=='E'){ + if(j+1<w && sq[i][j+1]=='0'){ + j++; + wallj++; + } + else + dir = turn_left(dir); + } + else if(dir=='N'){ + if(i-1>=0 && sq[i-1][j]=='0'){ + i--; + walli--; + } + else + dir = turn_left(dir); + } + else if(dir=='W'){ + if(j-1>=0 && sq[i][j-1]=='0'){ + j--; + wallj--; + } + else + dir = turn_left(dir); + } + else if(dir=='S'){ + if(i+1<b && sq[i+1][j]=='0'){ + i++; + walli++; + } + else + dir = turn_left(dir); + } + + if(i==b-1 && j==0) + returned = true; + } + + int visited[5]={0}; + for(int i=0; i<b; i++){ + for(int j=0; j<w; j++){ + if(count[i][j]>4) + continue; + else if(sq[i][j]=='0') + visited[count[i][j]]++; + } + } + for(int k=0; k<5; k++) + cout<<visited[k]<<" "; + cout<<endl; + cin>>b>>w; + } +} + +char turn_left(char dir){ + char new_dir; + if(dir=='E') + new_dir = 'N'; + else if(dir=='N') + new_dir = 'W'; + else if(dir=='W') + new_dir = 'S'; + else if(dir == 'S') + new_dir = 'E'; + return new_dir; +} + +char turn_right(char dir){ + char new_dir; + if(dir=='E') + new_dir = 'S'; + else if(dir=='N') + new_dir = 'E'; + else if(dir=='W') + new_dir = 'N'; + else if(dir == 'S') + new_dir = 'W'; + return new_dir; +} diff --git a/average/average b/average/average Binary files differnew file mode 100755 index 0000000..557795a --- /dev/null +++ b/average/average diff --git a/average/average.cpp b/average/average.cpp new file mode 100644 index 0000000..5627b61 --- /dev/null +++ b/average/average.cpp @@ -0,0 +1,119 @@ +#include <iostream> +#include <cmath> +#include <iomanip> +using namespace std; + +int find_gcd(int a, int b); +void printer(int c, int q, int num, int deno); + +int main(){ + int n, cnum=0; + cin>>n; + + while(n>0){ + cnum++; + int nm, sum=0; + for(int i=0; i<n; i++){ + cin>>nm; + sum += nm; + } + int gcd; + int deno, num, q; + if(abs(sum)>=n){ + if(sum % n == 0){ + num = sum/n; + deno = 0; + q = 0; + } + else{ + gcd = find_gcd(sum,n); + while(gcd != 1){ + sum /= gcd; + n /= gcd; + gcd = find_gcd(sum,n); + } + q = (sum-(sum%n))/n; + num = sum%n; + deno = n; + } + } + else{ //abs(sum)<n + gcd = find_gcd(n,sum); + while(gcd != 1){ + sum /= gcd; + n /= gcd; + gcd = find_gcd(n,sum); + } + q = 0; + num = sum; + deno = n; + } + printer(cnum, q, num, deno); + cin >> n; + + } +} + +void printer(int c, int q, int num, int deno){ + int dl=0, ql=0, nl=0, x=deno, y=q, z = num; + while (x /= 10) + dl++; + while(y /= 10) + ql++; + while(z /= 10) + nl++; + if(deno == 1 || deno == 0){ + if(num<0) + cout<<"Case "<<c<<":\n"<<"- "<<abs(num)<<endl; + else + cout<<"Case "<<c<<":\n"<<num<<endl; + } + else if(q == 0){ + if(num<0 || deno<0){ + cout<<"Case "<<c<<":\n"; + for(int k=0;k<dl+2;k++) cout<<" "; + cout<<abs(num)<<endl; + cout<<"- "; + for(int k=0;k<dl+1;k++) cout<<"-"; + cout<<endl; + cout<<" "<<abs(deno)<<endl; + } + else{ + cout<<"Case "<<c<<":\n"; + for(int k=0;k<dl;k++) cout<<" "; + cout<<abs(num)<<endl; + for(int k=0;k<dl+1;k++) cout<<"-"; + cout<<endl; + cout<<abs(deno)<<endl; + } + } + else{ + if(num<0 || deno<0){ + cout<<"Case "<<c<<":\n"; + for(int k=0;k<dl+2+ql-nl+1;k++) cout<<" "; + cout<<abs(num)<<endl; + cout<<"- "<<abs(q); + for(int k=0;k<dl+1;k++) cout<<"-"; + cout<<endl; + for(int k=0;k<3+ql;k++) cout<<" "; + cout<<abs(deno)<<endl; + } + else{ + cout<<"Case "<<c<<":\n"; + for(int k=0;k<dl+1+ql-nl;k++) cout<<" "; + cout<<num<<endl; + cout<<q; + for(int k=0;k<dl+1;k++) cout<<"-"; + cout<<endl; + for(int k=0;k<2+ql-1;k++) cout<<" "; + cout<<deno<<endl; + } + } +} + +int find_gcd(int a, int b){ + if(b==0) + return a; + else + return find_gcd(b, a % b); +} diff --git a/average/average.in b/average/average.in new file mode 100644 index 0000000..6ae00d8 --- /dev/null +++ b/average/average.in @@ -0,0 +1,8 @@ +2 -1 1 +100 4 -1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 +100 -8 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 -1 1 +1 -10000 +1 10000 +100 -909 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 -10000 +100 -99 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 10000 +0 diff --git a/lonesome/lonesome.cpp b/lonesome/lonesome.cpp new file mode 100644 index 0000000..8c13b11 --- /dev/null +++ b/lonesome/lonesome.cpp @@ -0,0 +1,38 @@ +#include <iostream> +using namespace std; + +int main() +{ + int dur; + cin>>dur; + while(dur>0) + { + int deprecs, months, depmonth, i; + double dwp, amt, val, cur_depval, iments, deps[100]={0.0}; + bool nend; + + cin>>dwp>>amt>>deprecs; + for(i=0;i<deprecs;i++) + cin>>depmonth>>deps[depmonth]; + + val = dwp+amt; + iments = amt/dur; + nend = true; + + for(months=0; ; ++months) + { + if(deps[months]>0) + cur_depval=deps[months]; + val -= val*cur_depval; + if(val>amt) + break; + amt -= iments; + } + if(months==1) + cout<<months<<" month\n"; + else + cout<<months<<" months\n"; + cin>>dur; + } + return 0; +} Binary files differdiff --git a/rfp/rfp.cpp b/rfp/rfp.cpp new file mode 100644 index 0000000..2a4f918 --- /dev/null +++ b/rfp/rfp.cpp @@ -0,0 +1,37 @@ +#include <iostream> +#include <string> +using namespace std; + +int main(){ + float req, pro; + cin>>req>>pro; + int rfpnum=0; + while(req>0) + { + int i, j, k; + float cost,curcost=1000000000, comp, curcomp=0, numcomp; + string trash, curname, name; + ++rfpnum; + for(i=0; i<=req; i++) + getline(cin, trash); + + for(j=0; j<pro; j++){ + getline(cin, name); + cin>>cost>>numcomp; + comp = numcomp/req; + + if(comp>curcomp || (comp==curcomp && cost<curcost)){ + curname = name; + curcomp = comp; + curcost = cost; + } + + for(k=0;k<=numcomp;k++) + getline(cin, trash); + } + if(rfpnum>1) cout<<"\n"; + cout<<"RFP #"<<rfpnum<<"\n"<<curname<<"\n"; + cin>>req>>pro; + } + return 0; +} diff --git a/rfp/rfp.in b/rfp/rfp.in new file mode 100644 index 0000000..f0bc2d6 --- /dev/null +++ b/rfp/rfp.in @@ -0,0 +1,32 @@ +6 4 +engine +brakes +tires +ashtray +vinyl roof +trip computer +Chevrolet +20000.00 3 +engine +tires +brakes +Cadillac +70000.00 4 +ashtray +vinyl roof +trip computer +engine +Hyundai +10000.00 3 +engine +tires +ashtray +Lada +6000.00 1 +tires +1 1 +coffee +Starbucks +1.50 1 +coffee +0 0
\ No newline at end of file |
