UCF Local Programming Contest 2016 March 28, 2020

Keywords: C++

A. Majestic 10

Title: Give you three numbers. You can tell how many of them are big fish equal to 10 and print the relevant output according to the number.

Solution: This is a simple check-in question, simple.

Code:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 #define ll long long
 5 using namespace std;
 6 int main(){
 7     ll n;
 8     cin>>n;
 9     while(n--){
10         int num=0,t;
11         int cnt[3]={0},tt=0; 
12         for(int i=0;i<3;i++){  
13             cin>>t;
14             cnt[tt++]=t;
15             if(t>=10){
16                 num++;
17             }
18         }
19         for(int i=0;i<tt;i++){
20             cout<<cnt[i];
21             if(i<tt-1){
22                 cout<<" ";
23             }else{
24                 cout<<endl;
25             }
26         }
27         if(num==0){
28             cout<<"zilch"<<endl;
29         }else if(num==1){
30             cout<<"double"<<endl;
31         }else if(num==2){
32             cout<<"double-double"<<endl;
33         }else{
34             cout<<"triple-double"<<endl;
35         }
36         cout<<endl;
37     }
38     return 0;
39 } 

B. Phoneme Palindromes

Title meaning: Probably to tell if the two strings given by the title are palindrome strings or not, but a bit innovative is to give the two letters that can be considered identical even if they are different. This input below will show that the two letters match this feature

Solution: According to the conventional palindrome string judgment method, when encountering a non-palindrome string, you can replace the "ambiguous" letters in both strings and compare them.

Code:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<map>
 4 #include<algorithm>
 5 using namespace std;
 6 #define ll long long
 7 int main(){    
 8     ll n,p,q;
 9     string ptr1;
10     char c1,c2;
11     cin>>n;
12     int num=1;
13     while(n--){
14         cin>>p;
15         map<char,char> mp;
16         for(int i=0;i<p;i++){
17             cin>>c1>>c2;
18             mp[c1]=c2;
19         }
20         cin>>q;
21         cout<<"Test case #"<<num<<":"<<endl;
22         num++;
23         for(int i=0;i<q;i++){//This is judgment 
24             cin>>ptr1;
25             string pr=ptr1;//Original 
26             string ptr2(ptr1.rbegin(),ptr1.rend());
27             if(ptr1==ptr2){
28                 cout<<pr<<" "<<"YES"<<endl;
29             }else{
30                 for(int j=0;j<ptr2.length();j++){
31                     if(mp.count(ptr2[j])!=0){//Indicates existence 
32                         ptr2[j]=mp[ptr2[j]];
33                     }
34                 }
35                 for(int j=0;j<ptr1.length();j++){
36                     if(mp.count(ptr1[j])!=0){
37                         ptr1[j]=mp[ptr1[j]];
38                     }
39                 }
40                 if(ptr1==ptr2){
41                     cout<<pr<<" "<<"YES"<<endl;
42                 }else{
43                     cout<<pr<<" "<<"NO"<<endl;
44                 }
45             }
46         }
47         cout<<endl;
48     }
49     return 0;
50 }

C. Don't Break the Ice

Title: Maybe it means giving you a board full of ice. You can hit any one of the ice cubes and the ice will fall back, but its fall will be a chain reaction and the ice next to it will fall, unless the ice next to it is in a complete row or column, and the ice that falls will also affect other ice cubes in the same way.It would be redundant for you to ask a few of the steps given below.

Question: The meaning of this question is relatively simple. Simple violence can simulate the whole process, but the process is more complex and careful.

Code:

 1 #include<iostream>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 #define ll long long
 6 ll D,N,x,y; 
 7 ll num[100][100]={0};
 8 int net[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
 9 bool check(int dx,int dy){
10     return (dx>=1&&dy<=D)&&(dy>=1&&dy<=D);    
11 } 
12 int main(){
13     ll n;//Number of samples
14     cin>>n;
15     int g=1;
16     while(n--){
17         cin>>D>>N;
18         for(int i=1;i<=D;i++){
19             for(int j=1;j<=D;j++){
20                 num[i][j]=1;
21             }
22         }//Initialized to 1 means there is ice at this location 
23         ll sum=0;//Store Answers 
24         for(int i=0;i<N;i++){//Enter every action 
25             cin>>x>>y;
26             if(num[x][y]==0){//This operation is invalid 
27                 sum++;
28             }else{//This operation is valid 
29                 num[x][y]=0;//Indicates that this ice cube has fallen back, starting from its center 
30                 //But it affects the ice around it
31                 for(int j=0;j<4;j++){
32                     int dx=x+net[j][0];
33                     int dy=y+net[j][1];
34                     if(check(dx,dy)&&num[dx][dy]==1){
35                         if(j==0){//Move right 
36                             for(int r=dy;r<=D;r++){
37                                 int ff=0;
38                                 for(int rr=1;rr<=D;rr++){
39                                     if(num[rr][r]==1){
40                                         ff++;
41                                     }
42                                 }
43                                 if(ff==D){}
44                                 else {//Incomplete 
45                                     num[dx][r]=0;
46                                 }
47                             }
48                         }else if(j==1){//left 
49                             for(int r=dy;r>=1;r--){
50                                 int ff=0;
51                                 for(int rr=1;rr<=D;rr++){
52                                     if(num[rr][r]==1){
53                                         ff++;
54                                     }
55                                 }
56                                 if(ff==D){}
57                                 else{//Incomplete 
58                                     num[dx][r]=0;
59                                 }
60                             }
61                         }else if(j==2){//Move up 
62                             for(int r=dx;r<=D;r++){
63                                 int ff=0;
64                                 for(int rr=1;rr<=D;rr++){
65                                     if(num[r][rr]==1){
66                                         ff++;
67                                     }
68                                 }
69                                 if(ff==D){}
70                                 else{
71                                     num[r][dy]=0;
72                                 }
73                             }
74                         }else if(j==3){//Move down 
75                             for(int r=dx;r>=1;r--){
76                                 int ff=0;
77                                 for(int rr=1;rr<=D;rr++){
78                                     if(num[r][rr]==1){
79                                         ff++;
80                                     }
81                                 }
82                                 if(ff==D){}
83                                 else{//Incomplete 
84                                     num[r][dy]=0;
85                                 }
86                             }
87                         }
88                     }
89                 }
90             }
91         }
92         cout<<"Strategy #"<<g<<": "<<sum<<endl;
93         g++;
94         cout<<endl;
95     } 
96     return 0;
97 }

E. Loopy Word Search

Title: Title is relatively simple, that is, you want to find a string in the title of the letter "matrix" in the first letter appear in the location and direction

The only trick is to flip the letter "matrix" given in the title to enlarge the length of the string.

Code:

  1 #include<iostream>
  2 #include<cstring>
  3 #include<algorithm>
  4 using namespace std;
  5 #define ll long long
  6 int main(){
  7     ll n;
  8     cin>>n;
  9     ll r,c; 
 10     string arr;
 11     ll num;
 12     int g=1;
 13     while(n--){//Number of puzzles 
 14         scanf("%d %d",&r,&c);//Rows and Columns
 15         char ptr[100][100];
 16         for(int i=1;i<=r;i++){
 17             for(int j=1;j<=c;j++){
 18                 cin>>ptr[i][j];
 19             }
 20         }
 21         string ar[100],ac[100];
 22         int    ir=1,   ic=1;
 23         for(int i=1;i<=r;i++){//Here the rows are concatenated and stored in an array 
 24             string temp;
 25             for(int j=1;j<=c;j++){
 26                 temp=temp+ptr[i][j];
 27             }
 28             ar[ir++]=temp;
 29         }
 30         for(int i=1;i<=c;i++){//Here the columns are concatenated and stored in an array 
 31             string temp;
 32             for(int j=1;j<=r;j++){
 33                 temp=temp+ptr[j][i];
 34             }
 35             ac[ic++]=temp;
 36         }
 37         cin>>num;
 38         cout<<"Word search puzzle #"<<g<<":"<<endl;
 39         g++;
 40         for(int i=0;i<num;i++){
 41             cin>>arr;
 42             int front=0;//The direction the record is looking for is that
 43             int x,y;//Coordinates for the first letter 
 44             int f=0;//Whether the marker was found
 45             if(f==0){//Travel smoothly   
 46                 for(int j=1;j<ir;j++){//Traverse through each row element 
 47                     string temp;
 48                     while(temp.length()<=10000){
 49                         temp=temp+ar[j];
 50                     }
 51                     //Start looking below
 52                     int dis=temp.find(arr);
 53                     if(dis!=-1){//Find the coordinates of the row and column where you want to record the first occurrence 
 54                         x=j;
 55                         y=dis+1;
 56                         f=1;//Tag found
 57                         front=1;//Towards the right 
 58                         break; 
 59                     }else{}//Indicates not found 
 60                 }
 61             } 
 62             if(f==0){//Retrograde 
 63                 for(int j=1;j<ir;j++){//Traverse through each row element 
 64                     string temp;
 65                     string s(ar[j].rbegin(),ar[j].rend());
 66                     while(temp.length()<=10000){
 67                         temp=temp+s;
 68                     }
 69                     int dis=temp.find(arr);
 70                     if(dis!=-1){//Finding the following difficult point is recording where it occurs 
 71                         x=j;
 72                         y=s.length()-1-dis+1;
 73                         f=1;
 74                         front=2;//Towards the left 
 75                         break;
 76                     }else{}//No, 
 77                 }
 78             }
 79             if(f==0){//Listing(From top to bottom) 
 80                 for(int j=1;j<ic;j++){//Traverse through each column element 
 81                     string temp;
 82                     while(temp.length()<=10000){
 83                         temp=temp+ac[j];
 84                     }
 85                     int dis=temp.find(arr);
 86                     if(dis!=-1){//Finding the coordinates of the rows and columns is now the main task 
 87                         x=dis+1;
 88                         y=j;
 89                         front=3;//down 
 90                         f=1;
 91                         break;
 92                     }else{}//Can't find 
 93                 } 
 94             } 
 95             if(f==0){//Column inverse (From bottom to top) 
 96                 for(int j=1;j<ic;j++){//Traverse through each 
 97                     string temp;
 98                     string s(ac[j].rbegin(),ac[j].rend());
 99                     while(temp.length()<=10000){
100                         temp=temp+s;
101                     }
102                     int dis=temp.find(arr);
103                     if(dis!=-1){//Find the rows and columns that are now predominantly identifying the first letter 
104                         x=s.length()-1-dis+1;
105                         y=j;
106                         f=1;
107                         front=4;//down 
108                         break;
109                     }else{}//Can't find 
110                 }
111             } 
112             if(front==1) cout<<"R ";
113             if(front==2) cout<<"L ";
114             if(front==3) cout<<"D ";
115             if(front==4) cout<<"U ";
116             cout<<x<<" "<<y<<" ";
117             cout<<arr<<endl;
118         }//After data entry, start processing the data below
119         cout<<endl;
120     }
121     return 0;
122 }

Posted by lozza1978 on Mon, 30 Mar 2020 18:33:08 -0700