Translate

Views

Tuesday, July 26, 2022

Solution UVa: 10205 - Stack 'em Up


 Link Problem: http://uva.onlinejudge.org/external/102/10205.pdf

Click on table to read problem, udebug, discuss!

 Last Submissions
  Problem  VerdictLangTimeBestRankSubmit Time
 | discuss10205 - Stack 'em Up AcceptedC++110.0000.00012944 mins ago



#include<bits/stdc++.h>
using namespace std;

int t, n, k;
int a[1001][1001];
string val[13] = {"2", "3", "4", "5", "6", "7", "8", "9", "10", "Jack", "Queen", "King", "Ace"};
string suit[4] = {"Clubs", "Diamonds", "Hearts", "Spades"};
string s;  

int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin >> t;
    while(t--){
        cin >> n;
        for(int i=1; i<=n; i++)
            for(int j=1; j<=52; j++)
                cin >> a[i][j];
       
        vector<string> as;
        as.push_back("code by ncc02");
        for(int i=0; i<4; i++)
            for(int j=0; j<13; j++)
                as.push_back(val[j] + " of " + suit[i]);
       
       
        cin.ignore();
        while(getline(cin, s) && s.size()){
            k= stoi(s);
            vector<string> t= as;
           
            for(int j=1; j<=52; j++)
                as[j]= t[ a[k][j] ];
        }
       
        for(int j=1; j<=52; j++)
            cout<<as[j]<<"\n";
        cout<<(t?"\n":"");
    }
}

Monday, July 25, 2022

Solution UVa: 11687 - Digits

 

Link Problem: http://uva.onlinejudge.org/external/116/11687.pdf


 Problem  VerdictLangTimeBestRankSubmit Time
 | discuss11687 - Digits AcceptedC++110.0000.00070015 mins ago


#include<bits/stdc++.h>
using namespace std;

int main(){
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

string s;
while(cin >> s && s!="END"){
int cnt= 0;
while(s != to_string(s.size())){
s= to_string(s.size());
cnt++;
}
cout<<cnt+1<<"\n";
}
}

Sunday, July 24, 2022

Solution UVa: 13025 - Back to the Past


Link Problem: https://onlinejudge.org/external/130/13025.pdf 


My Submissions

#ProblemVerdictLanguageRun TimeSubmission Date
2767512013025Back to the PastAcceptedC++110.0002022-07-24 10:11:26


#include<bits/stdc++.h>
using namespace std;

string StringByIndex(int index){
if (index== 2) return "Monday";
if (index== 3) return "Tuesday";
if (index== 4) return "Wednesday";
if (index== 5) return "Thursday";
if (index== 6) return "Friday";
if (index== 7) return "Saturday";
if (index== 8) return "Sunday";
}

string NameMonth(int monthPast){
if (monthPast== 1) return "January";
if (monthPast== 2) return "February";
if (monthPast== 3) return "March";
if (monthPast== 4) return "April";
if (monthPast== 5) return "May";
if (monthPast== 6) return "June";
if (monthPast== 7) return "July";
if (monthPast== 8) return "August";
if (monthPast==9) return "September";
if (monthPast==10) return "October";
if (monthPast==11) return "November";
if (monthPast==12) return "December";
}

string TheNameOfWeekDay(int index, int dayNow, int monthNow, int yearNow, int dayPast, int monthPast, int yearPast){
bool leapYear= (yearNow%4==0 && yearNow%100!=0);
while (dayNow != dayPast && monthNow != monthPast && yearNow != yearPast){
dayNow--;
index--;
if (index==1) index= 8;
if (dayNow == 0){
monthNow--;
if (monthNow==0){
yearNow--;
leapYear= (yearNow%4==0 && yearNow%100!=0);
monthNow= 12;
dayNow=31;
}
if (monthNow==1 || monthNow==3 ||monthNow==5||monthNow==7 ||monthNow==8 ||monthNow==10 ||monthNow==12){
dayNow= 31;
}
else
if (monthNow == 2){
if (leapYear) dayNow=29;
else dayNow=28;
}
else dayNow=30;
}
}
return NameMonth(monthPast)+" "+to_string(dayPast)+", "+to_string(yearPast)+" "+ StringByIndex(index);
}


int main(){
int index= 8; //The name day of week day now : Sunday
int dayNow= 24;
int monthNow= 7;
int yearNow= 2022;
int dayPast= 29;
int monthPast= 5;
int yearPast= 2013; 
cout<<TheNameOfWeekDay(index, dayNow, monthNow, yearNow, dayPast, monthPast, yearPast)<<"\n";
}

Friday, July 22, 2022

Solution Kattis - Architecture


Link Problem:  https://open.kattis.com/problems/architecture


Submission 9161708

IDDATEPROBLEMSTATUSCPULANGTEST CASES
916170818:41:44Architecture
Accepted
0.00 sC++
52/52

Files submitted

architecture.cpp

#include<bits/stdc++.h>
using namespace std;
int r, c, x, y, X=0, Y=0;
int main(){
cin >> r >> c;
while(r--){
cin >> x;
X= max(X, x);
}
while(c--){
cin >> y;
Y= max(Y, y);
}
cout<<(X==Y?"possible":"impossible");
}

Thursday, July 21, 2022

Solution Kattis - Anthony and Diablo


Link Problem: https://open.kattis.com/problems/anthonyanddiablo  


Submission 9157740

IDDATEPROBLEMSTATUSCPULANGTEST CASES
915774019:52:37Anthony and Diablo
Accepted
0.00 sC++
13/13


Files submitted

anthonyanddiablo.cpp

#include<bits/stdc++.h>
#define PI 3.1415926
using namespace std;
int main(){
double a, n;
cin >> a >> n;
double r= n/(2*PI);
if (r*r*PI >= a) cout<<"Diablo is happy!";
else cout<<"Need more materials!";
}

Wednesday, July 20, 2022

Solution Kattis - Beekeeper


Link Problem: https://open.kattis.com/problems/beekeeper 


Submission 9153573

IDDATEPROBLEMSTATUSCPULANGTEST CASES
915357317:44:36Beekeeper
Accepted
0.00 sC++
2/2


Files submitted

beekeeper.cpp

#include<bits/stdc++.h>
using namespace std;
bool vowels(char x){
string s= "aeiouy";
for(int i=0; s[i]; i++)
if (s[i]==x) return true;
return false;
}
int f(string s){
int cnt= 0;
for(int i=0; s[i+1]; i++)
if (s[i]==s[i+1] && vowels(s[i])){
i++;
cnt++;
}
return cnt;
}
int main(){
int n;
while(cin >> n && n){
string res;
int MAX= -1; //0 => wa
for(int i=1; i<=n; i++){
string s; cin >> s;
if (f(s) > MAX){
MAX = f(s);
res= s;
}
}
cout<<res<<"\n";
}
}