Gui Telecommunications 2020 Program Design Competition Problem Solution

A is
equivalent to hello world, that is, one more a to control the number

//A
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int t;
	cin>>t;
	while(t--){
    
    
		int a;
		cin>>a;
		for(int i=0;i<a-1;i++){
    
    
			cout<<"AC "; 
		}
		cout<<"AC"<<endl;
	}
	return 0;
}

B
sorting
This data volume can be sorted by bubble sorting

//B
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int a[20005];
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
    
    
		cin>>a[i];
	}
	sort(a,a+n);
	for(int i=0;i<n;i++){
    
    
		cout<<a[i]<<" ";
	}
	return 0;
}

C
palindrome number, because there are only four digits, use four variables to store the four-digit ones, ten, hundred, and thousand, and then traverse 1001~9999

//C
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int a,b,c,d;
	for(int i=1001;i<=9999;i++){
    
    
		a=i%10;//个位 
		b=(i%100)/10;//十位 
		c=(i%1000)/100;//百位
		d=(i%10000)/1000;//千位 
		if(a==d&&b==c) cout<<i<<endl;
	}
	return 0;
}

D
01 string, output binary within 128, you can directly open the array to write binary simulation, and enter one every two. I wrote a ten-to-two function directly, and I was lazy.

//D
#include<bits/stdc++.h>
using namespace std;
void stob(int num){
    
    
	int n=num;
	int k=0;
	int a[7];
	while(num>1){
    
    
		a[k++]=num%2;
		num/=2;
	}
	a[k]=num;
	for(int i=6;i>k;i--){
    
    
		cout<<0;
	}
	for(int i=k;i>=0;i--){
    
    
		cout<<a[i];
	}
	cout<<endl;
}
int main(){
    
    
	for(int i=0;i<=127;i++){
    
    
		stob(i);
	}
	return 0;
}

E
converts lowercase to uppercase
. The first letter is directly converted, and the space after the space is converted to uppercase.
Use getline() for input, a line of string input, which can include spaces.
Then there is always a small error in normal writing, so I put the input into the while(), this kind of oj judgment can pass, and the compiler is stuck

//E
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int t;
	cin>>t;
	string s;
	while(getline(cin,s)){
    
    
		s[0]-=32;
		for(int i=1;i<s.size();i++){
    
    
			if(s[i]==' ') s[i+1]-=32;
		}
		cout<<s<<endl;
	}
	return 0;
}

F
thinking questions

#include<bits/stdc++.h>
using namespace std;
int a[21][21];
int main(){
    
    
	int t;
	cin>>t;
	while(t--){
    
    
		int n,k;
		cin>>n;
		memset(a,0,sizeof(a));
		vector<int> ve;
		for(int i=1;i<=n;i++){
    
    
			for(int j=1;j<=n;j++){
    
    
				cin>>k;
				if(k==1&&a[j][i]==0&&i!=j) a[i][j]=1;
				if(k==1&&a[j][i]==1&&i!=j) ve.push_back(i),ve.push_back(j);
			}
		}
		sort(ve.begin(),ve.end());
		for(int i=0;i<ve.size();i++){
    
    
			cout<<ve[i]<<" ";
		}
		cout<<endl;
	}
}

G
This is a question taken from the Blue Bridge Cup. You
can see the idea at a glance. Use recursion. Be patient and find An and Sn, and they will come out.

//G
#include<bits/stdc++.h>
using namespace std;
void An(int n){
    
    
    for(int i=1;i<=n;i++){
    
    
        cout<<"sin("<<i;
        if(i%2!=0&&i!=n){
    
    
            cout<<"-";
        }
        if(i%2==0&&i!=n){
    
    
            cout<<"+";
        }
    }
    for(int i=0;i<n;i++){
    
    
        cout<<")";
    }
}
void Sn(int n){
    
    
    int d=n;
    for(int i=0;i<n-1;i++){
    
    
        cout<<"(";
    }
    for(int i=1;i<=n;i++){
    
    
        An(i);
        cout<<"+"<<d;
        if(d!=1) cout<<")";
        d--;
    }
}
int main(){
    
    
	int t;
	cin>>t;
	while(t--){
    
    
		int n;
		cin>>n;
		Sn(n);
		cout<<endl;
	}
	return 0;
}


Question H is said to be the shortest path. There are negative side weights, no negative loops, and the data range is not large. It can be found with floyd, but the test sample has never been tested. It may be that I have not understood the algorithm enough.

#include<bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3f
#define M 1305
int maps[M][M];
int n,m;
int u,v,l;
void floyd(){
    
    
	for(int k=1;k<=n;k++){
    
    
		for(int i=1;i<=n;i++){
    
    
			for(int j=1;j<=n;j++){
    
    
				if(maps[i][j]>maps[i][k]+maps[k][j]){
    
    
					maps[i][j]=maps[i][k]+maps[k][j];
				}
			}
		}
	}
}
int main(){
    
    
    int t;
    cin>>t;
    while(t--){
    
    
        cin>>n>>m;
        for(int i=1;i<=n;i++){
    
    
        	for(int j=1;j<=n;j++){
    
    
        		maps[i][j]=INF;
			}
			maps[i][i]=0;
		}
        for(int i=0;i<m;i++){
    
    
        	cin>>u>>v>>l;
        	maps[u][v]=maps[v][u]=l;
		}
        floyd();
        for(int i=2;i<=n;i++){
    
    
        	cout<<maps[1][i]<<endl;
		}
    }
    return 0;
}

H* The
person who wrote the question made the wrong symbol, and it is still an H. Just call it H*.
Blue Bridge Cup sub-question-the price of perfection.

//Hh 回文
#include<bits/stdc++.h>
using namespace std;
void solve(){
    
    
    string s;
    int n,j,cnt=0,flag=0,index;
    cin>>n>>s;
    int last=n-1;
    for(int i=0;i<last;i++){
    
    
        for(j=last;j>i;j--){
    
    
            if(s[i]==s[j]){
    
    
                for(int u=j;u<last;u++) s[u]=s[u+1];
                s[last]=s[i];
                cnt+=last-j;
                last--;
                break;
            }
        }
        if(j==i&&(n%2==0||flag==1)){
    
    
            cout<<"Impossible"<<endl;
            return;
        }else if(j==i){
    
    
            flag=1;
            index=i;
        }
    }
    if(!flag) cout<<cnt<<endl;
    else cout<<cnt+n/2-index<<endl;
}
int main(){
    
    
	int t;
	cin>>t;
	while(t--){
    
    
		solve();
	}
	return 0;
} 

I presented
the simplest question of A in this field. Just one number in the first line, two numbers in the second line, and three numbers in the third line...
Set two variables by yourself, one to control the number of lines, and one to keep ++.

//I
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int t;
	cin>>t;
	while(t--){
    
    
		int m;
		cin>>m;
		int k=1;
		int p=1;
		for(int i=1;i<=m;i++){
    
    
			for(int j=1;j<=p;j++){
    
    
				cout<<k++;
			}
			p++;
			cout<<endl;
		}
	}
	return 0;
}

J
finds the interval and sorts it directly to the largest.
Two arrays were opened, one initial and one transition.

//J
#include<bits/stdc++.h>
using namespace std;
int main(){
    
    
	int t;
	cin>>t;
	while(t--){
    
    
		int n;
		int a[1005];
		memset(a,0,sizeof(a));
		cin>>n;
		for(int i=1;i<=n;i++){
    
    
			cin>>a[i];
		}
		int m;
		int b[1005];
		memset(b,0,sizeof(b));
		cin>>m;
		while(m--){
    
    
			int l,r,K;
			cin>>l>>r>>K;
			for(int i=0,j=l;j<=r;j++,i++){
    
    
				b[i]=a[j];
			}
			sort(b,b+r-l+1);
			cout<<b[r-l-K+1]<<endl;
		}
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/iuk11/article/details/108735433