UVA Problem 945 Bicoloring  Solution

UVA Problem 945 Bicoloring Solution

    #include<stdio.h> #include<string.h> int main() { int l,i,j,count=0; char s[100000]; while(gets(s)) { l=strlen(s); for(i=0;i<l;i++) { switch(s[i]) { case 'b': { for(j=0;j<count;j++) printf(" "); count=0; break; } case '1':...

UVA Problem 10168 Solution

UVA Problem 10168 Solution

  #include <stdio.h> #define N 10000000 typedef long long LL; using namespace std ; LL primes[N]; //bool flag[N]; void sieve(LL n) { for(LL i=4; i<=n; i+=2) { primes[i]=1; } //LL p=(LL)sqrt(n); for(LL i=3; i*i<=n; i+=2) { if(primes[i]) continue;...

UVA Problem 10340 (All in All) Solution

UVA Problem 10340 (All in All) Solution

    #include <bits/stdc++.h> using namespace std; char s[100000],t[100000]; int main() { int i,j; bool flag; while(scanf("%s %s",s,t)!=EOF) { flag=false; for(j=0,i=0;t[i]!='\0';i++) { if (s[j] == t[i]) j++; if (s[j] == '\0') { flag = true; break; } }...

UVA Problem 10550 (Combination Lock) Solution

UVA Problem 10550 (Combination Lock) Solution

#include <bits/stdc++.h> using namespace std; int main() { int a,b,c,d,res; while(cin>>a>>b>>c>>d) { if(a==0 and b==0 and c==0 and d==0) break; res=1080; res += (a > b) ? (a - b) * 9 : (a - b + 40) * 9; res += (c > b) ? (c - b) * 9...

UVA Problem 10976 (Fractions Again) Solution

UVA Problem 10976 (Fractions Again) Solution

    #include <bits/stdc++.h> using namespace std; int main() { int x,y,k,n,i,KK,X[10005],Y[10005]; bool f; KK=0; while(cin>>k) { KK=0; //X[105]=Y[105]={0}; memset(X, 0, sizeof(X[0]) * 10005); memset(Y, 0, sizeof(Y[0]) * 10005); for(y= 2*k ; y!=k;...

UVA Problem 11286 ( Conformity) Solution

UVA Problem 11286 ( Conformity) Solution

    #include <bits/stdc++.h> #include <algorithm> #include <vector> #include <map> #include <iostream> using namespace std; #define SIZE(a) ((int)a.size()) #define FOREACH(i, c) for (__typeof((c).begin()) i = (c).begin(); i !=...

UVA Problem 11364 ( Parking) Solution

UVA Problem 11364 ( Parking) Solution

    #include <bits/stdc++.h> using namespace std; int main() { int a[150],i,j,tc,n,sum; cin>>tc; while(tc--) { sum=0; cin>>n; for(i=0;i<n;i++) cin>>a[i]; sort(a,a+n); for(i=0;i<n-1;i++) sum+=abs(a[i]-a[i+1]); sum*=2;...

UVA Problem 12250 ( Language Detection) Solution

UVA Problem 12250 ( Language Detection) Solution

#include <bits/stdc++.h> using namespace std; int main() { char s[2001]; int cases=1,l; while(scanf("%s",s)) { if(strcmp(s,"#")==0) break; if(strcmp(s,"HELLO")==0) printf("Case %d: ENGLISH\n",cases++); else if(strcmp(s,"HOLA")==0) printf("Case %d:...

UVA Problem 12279 ( Emoogle Balance) Solution

UVA Problem 12279 ( Emoogle Balance) Solution

    #include <bits/stdc++.h> using namespace std; int main() { int tc,cases=1,n,a[1001],give,given,egl; while(cin>>n) { give=0,given=0; if (n==0) break; for(int i=0;i<n;i++) cin>>a[i]; for(int i=0;i<n;i++) if(a[i]==0) give++; else...

UVA Problem 12289 ( One-Two-Three) Solution

UVA Problem 12289 ( One-Two-Three) Solution

  #include <bits/stdc++.h> using namespace std; int main() { char s[101],l; int i,tc,ans; cin>>tc; while(tc--) { scanf("%s",s); l=strlen(s); if(l<=3) { if(s[0] =='o'&&s[1]=='n'&& s[2] == 'e' || s[0] == 'o' && s[1] == 'n' ||...

UVA Problem 12403 ( Save Setu ) Solution

UVA Problem 12403 ( Save Setu ) Solution

  #include <bits/stdc++.h> using namespace std; int main() { char s[150]; int tc,a,sum=0,amount; cin>>tc; while(tc--) { scanf("\r"); scanf("%s",s); if(strcmp(s,"donate")== 0) { cin>>amount; sum+=amount; //printf("%d\n",sum); } else...

UVA Problem 12577( Hajj-e-Akbar) Solution

UVA Problem 12577( Hajj-e-Akbar) Solution

  #include <bits/stdc++.h> using namespace std; int main() { char s[10]; int cases=1; while(scanf("%s",s)) { if(strcmp(s,"*")==0) break; else if( strcmp(s,"Hajj")== 0) printf("Case %d: Hajj-e-Akbar\n",cases++); else printf("Case %d:...

UVA Problem 336 (A Node Too Far) Solution

UVA Problem 336 (A Node Too Far) Solution

  #include<bits/stdc++.h> using namespace std; int tc=1,position=0; int bfs(int src, int TTL,map <int, vector<int> > edges) { map<int,int> visited,level; int unreach=0; queue<int>Q; Q.push(src); position=1; visited[src]=1;...

UVA Problem 10004 (Bicoloring) Solution

UVA Problem 10004 (Bicoloring) Solution

    #include <cstdio> #include <vector> #include <queue> using namespace std; typedef vector<int> vi; int main() { int V, E, u, v; vector<vi> AdjList; while (scanf("%d", &V), V) { AdjList.assign(V, vi()); scanf("%d",...

UVA Problem 490 (Rotating Sentences ) Solution

UVA Problem 490 (Rotating Sentences ) Solution

#include <bits/stdc++.h> #include <string> #include <vector> #include <map> using namespace std; int main() { string s; int frequency=0; vector<string>vec; while(getline(cin,s)) { v.push_back(s); frequency=max(frequency,(int)s.length());...

UVA Problem 496 ( Simply Subsets )Solution

UVA Problem 496 ( Simply Subsets )Solution

  #include <iostream> #include <string> #include <sstream> #include <vector> using namespace std; int main() { stringstream ss; string line1,line2; vector<int>A,B; int i,j,ch; while(getline(cin,line1) && getline(cin,line2)) {...