/* The structure of the node of the queue is struct QueueNode { int data; QueueNode *next; }; and the structure of the class is class Queue { private: QueueNode *front; QueueNode *rear; public : void push(int); int pop(); }; */ /* The method push to push element into the queue*/ void Queue:: push(int x)
Author: Asif Naeem
Encoding A String function
char *encode(char *src) { //Your code here int length = strlen(src); char *res=(char *)malloc(sizeof(char) * length); int a[5]; int idx=0; int cnt=1,n,pos; res[idx]=src[0]; for(int i=1;i<strlen(src);i++) { if(src[i]!=src[i-1]) { n=cnt; if(n>=10) { pos=-1; while(n) { pos+=1; a[pos]=n%10; n/=10; } while(pos>=0) { idx+=1; res[idx]=char(a[pos–]+'0'); } } else { idx+=1; res[idx]=char(cnt+'0'); } idx+=1; res[idx]=src[i]; cnt=1; } else {
Stack with LinkedList
void push(int x) { StackNode *tmp=new StackNode; tmp->data=x; tmp->next=top; top=tmp; } /*The method pop which return the element poped out of the stack*/ int pop() { int v; StackNode *q; if(top!=NULL) { q=top; v=top->data; top=top->next; delete(q); return v; } else return -1; }
10166
#include <iostream> #include <algorithm> #include <queue> #include <cstdio> #include <cstring> #include <string> #include <map> #include <vector> using namespace std; struct Schedule{ int to; int start,end; Schedule(int a,int b,int c) { to = a; start = b; end = c; } }; vector<Schedule> vb[101]; int kase=1; map<string,int> mp; char dest_city[1024], start_city[1024]; int earliest_start_time, cityNum; int dist[2400][101];//saves
10039
#include <iostream> #include <algorithm> #include <queue> #include <cstdio> #include <cstring> #include <string> #include <map> #include <vector> using namespace std; struct Schedule{ int to; int start,end; Schedule(int a,int b,int c) { to = a; start = b; end = c; } }; vector<Schedule> vb[101]; int kase=1; map<string,int> mp; char dest_city[1024], start_city[1024]; int earliest_start_time, cityNum; int dist[2400][101];//saves
10170
#include <iostream> #include <cstdio> #define ul unsigned long long//double//long long using namespace std; int main() { ul s,d,a,b; ul subtract; ul lw,hi,mid,res; while(scanf("%llu%llu",&s,&d)!=EOF) { if(d<=s) { printf("%llu\n",s); continue; } subtract=(s*(s-1))/2; lw=s; hi=s+d/s; res=-1; while(hi-lw>1) { mid=(lw+hi)/2; if(((mid*(mid+1))/2-subtract) <d) lw=mid+1; else if(((mid*(mid+1))/2-subtract)>d) hi=mid; else if(((mid*(mid+1))/2-subtract)==d) { res=mid; break; } } if(res!=-1) printf("%llu\n",res); else { //cout<<lw<<" "<<hi<<"\n";
974
#include <iostream> #include <cstdio> #include <cstring> #include <string> #include <vector> #define ll long long using namespace std; ll arr[40001]; vector<int> vb; ll _pow(int pwr) { if(pwr==0) return 1; else return 10*_pow(pwr-1); } bool Isfunc(ll a,int b) { int tmp; tmp=a; int pwr=0; int num=0; while(tmp) { num=num + (tmp%10)*_pow(pwr); tmp/=10; if(tmp+num==b && tmp!=0 && num!=0)
696
#include <iostream> #include <cstdio> using namespace std; int main() { int r,c,tmp,res; int row,col; //FILE *fp; //fp=fopen("out.txt","w"); while(scanf("%d%d",&r,&c)) { if(r+c==0) break; if((r==1 || c==1) || r==0 || c==0) { printf("%d knights may be placed on a %d row %d column board.\n",r*c,r,c); //fprintf(fp,"%d knights may be placed on a %d row %d column board.\n",r*c,r,c); continue; }
661
#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int capacity[21]; bool isTurnOn[21]; int main() { int n,m,c; int MX=0; int device; int kase=1; bool IsFUSE; long long total; while(scanf("%d%d%d",&n,&m,&c)) { if(n+m+c==0) break; //memset(capacity,0,sizeof(capacity)); //memset(isTurnOn,0,sizeof(isTurnOn)); IsFUSE=0; for(int i=1;i<=n;i++) { scanf("%d",&capacity[i]); isTurnOn[i]=0; } total=0; MX=0; for(int i=1;i<=m;i++) { scanf("%d",&device); if(IsFUSE) continue; if(isTurnOn[device]==0) { isTurnOn[device]=1;
594
#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; int main() { int n,res; int positionInByte,byteNo; while(scanf("%d",&n)!=EOF) { res=0; for(int i=0;i<32;i++) { if((1<<i)&n) { byteNo=i/8; positionInByte=i%8; res |= (1<<((3-byteNo)*8+positionInByte)); } } printf("%d converts to %d\n",n,res); } return 0; }