Posts

Showing posts from September, 2019

UVA 353

#include<bits/stdc++.h> using namespace std; int main() {     //freopen("input.txt","r",stdin);     //freopen("output.txt","w",stdout);     string a,b;     int flag;     while(getline(cin,a))     {         set<string>s1;         for(int i=0; i<a.size(); i++)         {             for(int j=i; j<a.size(); j++)             {                 vector<char>v;                 char c[1000];                 for(int k=i; k<=j; k++)                 {                     v.push_back(a[k]);                 }       ...

UVA 401

#include<bits/stdc++.h> using namespace std; int main() {     //freopen("input.txt","r",stdin);     //freopen("output.txt","w",stdout);     string a;     int flag,flag1;     while(getline(cin,a))     {         vector<char>b;         for(int i=0; i<a.size()/2; i++)         {             if(a[i]==a[a.size()-i-1])             {                 flag=0;             }             else             {                 flag=1;                 break;             }         }         int flag3=0;    ...

UVA 11586

#include<bits/stdc++.h> using namespace std; int main() {     //freopen("input.txt","r",stdin);     //freopen("output.txt","w",stdout);     int a,flag,sum=0,sum1=0,sum2=0;     string b;     cin>>a;     getchar();     for(int i=0; i<a; i++)     {         getline(cin,b);         //cout<<b<<endl;         for(int i=0; i<b.size()-1; i++)         {             //cout<<b[i]<<" "<<b[i+1]<<endl;             if(b[i]=='F' && b[i+1]=='M')             {                 sum++;             }             else if(b[i]=='M' && b[i+1]=='F')         ...

UVA 11683

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,c;     while(cin>>a)     {         if(a==0)         {             break;         }         cin>>b;         vector<int>v;         for(int i=0; i<b; i++)         {             cin>>c;             v.push_back(abs(a-c));         }         int m=v[0],sum=0;         sum=sum+v[0];         for(int i=1; i<b; i++)         {             if(v[i]>m && v[i]>v[i-1])             {                 sum=sum+(v[i...

UVA 11661

#include<bits/stdc++.h> using namespace std; int main() {     int a,b,sum,sum1;     string c;     while(cin>>a)     {         if(a==0)         {             break;         }         getchar();         getline(cin,c);         vector<int>v;         sum=10e9;         sum1=10e9;         for(int i=0; i<a; i++)         {             if(c[i]=='Z')             {                 v.push_back(0);                 break;             }             else if(c[i]=='R')        ...

UVA 10919

#include<bits/stdc++.h> using namespace std; int main() {     //freopen("input.txt","r",stdin);     //freopen("output.txt","w",stdout);     int a,b,c,d,e,e1,sum=0,flag=0;     while(cin>>a)     {         if(a==0)         {             break;         }         cin>>b;         vector<int>v;         for(int i=0; i<a; i++)         {             cin>>c;             v.push_back(c);         }         sort(v.begin(),v.end());         for(int i=0; i<b; i++)         {             cin>>c>>d;             for(int j=...

UVA 10424

#include<bits/stdc++.h> using namespace std; int main() {     //freopen("input.txt","r",stdin);     //freopen("output.txt","w",stdout);     string a,b;     char c='a';     int sum=0,sum1=0,sum12=0,sum2=0,sum22=0;     vector<int>v;     vector<char>v1;     for(int i=0; i<26; i++)     {         sum=sum+1;         v.push_back(sum);     }     for(int i=0; i<26; i++)     {         v1.push_back(c);         c++;     }     while(getline(cin,a))     {         getline(cin,b);         for(int i=0; i<26; i++)         {             for(int j=0; j<a.size(); j++)             {       ...

UVA 10324

#include<bits/stdc++.h> using namespace std; int main() {     //freopen("input.txt","r",stdin);     //freopen("output.txt","w",stdout);     long long int a,b,c,flag,sum=0,e,sum1=0,e1,e2,e3;     string d;     while(cin>>d)     {         sum1++;         vector<long long int>v;         v.push_back(0);         for(int i=0; i<d.size(); i++)         {             sum=sum+(d[i]-'0');             v.push_back(sum);         }         cin>>a;         flag=1;         for(int i=0; i<a; i++)         {             cin>>b>>c;             if(flag==1)     ...

UVA 10141

This easy problem blow out my mind because of getchar() and not understanding conditions of strings. #include<bits/stdc++.h> using namespace std; int main() { //freopen("input.txt","r",stdin); // freopen("output.txt","w",stdout); int a,b,h,g,sum1=1,best; while(cin>>a>>b) { string c,d,f,name; double e,price; //sum1++; best=0; price=1e9; // string name; if(a+b==0) { break; } getchar(); for(int i=0; i<a; i++) { getline(cin,c); } for(int i=0; i<b; i++) { //getchar(); getline(cin,d); cin>>e>>g; getchar(); if(best<g) { best=g; name=d; price=e; } else if(best==g && price>e) { ...

FILE input output

https://www.geeksforgeeks.org/inputoutput-external-file-cc-java-python-competitive-programming/

UVA 661

*I thought it will be ampere rather than amperes for 1.It costs many WA. #include<bits/stdc++.h> using namespace std; int main() {     long long int a,b,c,d,e,f,sum=0,g,h=0,x=0,flag;     while(cin>>a>>b>>c)     {         x++;         if(a+b+c==0)         {             break;         }         vector<long long int>v1,v2,v3;         for(int i=0; i<a; i++)         {             cin>>d;             v1.push_back(d);         }         //sort(v1.begin(),v1.end());         for(int i=0; i<b; i++)         {             cin>>d;           ...

UVA 573

#include<bits/stdc++.h> using namespace std; int main() {     double a,b,c,d,e=0,f=0,sum=0;     while(cin>>a>>b>>c>>d)     {         if(a+b+c+d==0)         {             break;         }         e=d/100.0;         e=e*b;         while(f>0 || f<=a)         {             if(sum>=1)             {                 b=b-e;             }             if(b<0)             {                 b=0;             }             f=f+b;       ...

UVA 119

#include<bits/stdc++.h> using namespace std; int main() {     int a,c[100],f,e,x1=0;     char b[100][100],d[100],g[100][100];     while(cin>>a)     {         x1++;         if(x1>=2)         {             cout<<endl;         }         for(int i=0; i<a; i++)         {             cin>>b[i];             c[i]=0;         }         for(int i=0; i<a; i++)         {             cin>>d>>e>>f;             if(f!=0)             {                 for(int j=0; j<f; j++)      ...

UVA 12554

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     /*ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);*/     int a,sum=0,flag=0,l=0;     string b[105],c[16];     cin>>a;     c[0]="Happy";     c[1]="birthday";     c[2]="to";     c[3]="you";     c[4]="Rujia";     for(int i=0; i<a; i++)     {         cin>>b[i];     }     while(true)     {         for(int i=0; i<a; i++)         {             cout<<b[i]<<": ";             sum++;             //cout<<sum<<endl;             if(sum==12 || (sum...

UVA 12503

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     /*ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);*/     int a,c,d[101],e,f,g=0,l=0,sum=0,h;     string b;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>h;         getchar();         for(int k=0; k<h; k++)         {             getline(cin,b);             //cout<<b<<endl;             e=b.size();             if(e==4 || e==5)             {                 if(b=="LEFT")                 { ...

UVA 12015

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     /*ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);*/     int a,b,c=0,d[105];     cin>>a;     pair<int,string>p[105];     for(int i=0; i<a; i++)     {         for(int j=0; j<10; j++)         {             cin>>p[j].second>>p[j].first;             d[j]=p[j].first;         }         sort(d,d+10);         b=d[9];         cout<<"Case #"<<i+1<<":"<<endl;         for(int j=0; j<10; j++)         {             if(b==p[j].first)    ...

UVA 11679

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     /*ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);*/     ll a,b,c,d,e;     while(cin>>a>>b)     {         if(a+b==0)         {             break;         }         //vector<ll>v;         ll v[a];         memset(v,0,sizeof(v));         for(int i=0; i<a; i++)         {             cin>>v[i];         }         for(int i=0; i<b; i++)         {             cin>>c>>d>>e;           ...

UVA 10963

/* ID: Nipun Paul LANG: C++ PROB: God knows */ #include<bits/stdc++.h> using namespace std; typedef long long ll; int main() {     /*ios::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);*/     ll a,b,c,d;     cin>>a;     for(int i=0; i<a; i++)     {         cin>>b;         vector<ll>v;         for(int j=0; j<b; j++)         {             cin>>c>>d;             v.push_back(abs(c-d));         }         sort(v.begin(),v.end());         if(v[0]==v[v.size()-1])         {             cout<<"yes"<<endl;         }         else       ...

UVA 10114

#include<bits/stdc++.h> using namespace std; int main() {     double a,b,c,d,e,f,g[101],pay,carown;     int sum=0;     while(cin>>a>>b>>c>>d)     {         if(a<0)         {             break;         }         while(d--)         {             cin>>e>>f;             for(int i=e; i<101; i++)             {                 g[i]=f;             }         }         pay=c/a;         carown=(b+c)*(1-g[0]);         while(carown<c)         {             sum++;   ...