A
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin>>s;
cout<<"Welcome To Sword Art Online!";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
// cin >> t;
while (t--) solve();
return 0;
}
B
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fo(i, n, x) for (int i = x; i <= n; i++)
void solve() {
int n;
cin>>n;
int minn=(1<<30);
int x;
for (int i = 1; i <= n; i++){
cin>>x;
minn=min(minn,x);
}
fo(i,n,1)cout<<minn<<endl;
}
signed main() {
int t = 1;
//cin>>t;
while (t--) solve();
return 0;
}
C
#include <bits/stdc++.h>
using namespace std;
void solve() {
string s;
cin>>s;
if(s.size()==1){//字符串长度
cout<<"Yes";
return;
}
int i=0;//字符串从0开始
int j=s.size()-1;
while(i<j){
if(s[i]!=s[j]){
cout<<"No";
return;
}
i++,j--;
}
cout<<"Yes";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
// cin >> t;
while (t--) solve();
return 0;
}
D
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin >> n;
vector<int>a(n + 1);
fo(i, n, 1)cin >> a[i];
int x;
cin >> x;
for (int i = 1; i <= n; i++){
if (x == a[i]) {
cout << i << endl;
return ;
}
}
cout << "Not Found";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
E(本题按照题面要求模拟即可)
#include <bits/stdc++.h>
using namespace std;
void solve() {
int m,n;
cin>>m>>n;
int now=0;
for (int i = 1; i <= n; i++){
int x;
cin>>x;
if(x<0){
now+=x;
if(now<0)now=0;
}
else{
now+=x;
if(now>m)now=m;
}
}
cout<<now<<endl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
// cin >> t;
while (t--) solve();
return 0;
}
F
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ref(i,n,x) for(int i=x;i>=n;i--)
#define fo(i, n, x) for (int i = x; i <= n; i++)
int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1}; //八方搜索
bool inmap(int x,int y){
return x >= 1 && x <= n && y >= 1 && y <= m;
}//确保搜索的点在图里面
void solve() {
int n, m;
cin >> n >> m;
char a[200][200];
for (int i = 1 ; i= n; i++)
for (int j= 1 ;j<= m; j++)
cin >> a[i][j];
char ans[210][210];
for (int i = 1 ; i= n; i++)
for (int j= 1 ;j<= m; j++){
if (a[i][j] == '*') {
ans[i][j] = '*';
} else {
int cnt = 0;
for (int k = 0; k < 8; k++) {
int xx = dx[k] + i;
int yy = dy[k] + j;
if (inmap(xx, yy) && a[xx][yy] == '*') {
cnt++;
}
}
ans[i][j] = '0' + cnt; //变成数字
}
}
}
for (int i = 1 ; i= n; i++)
for (int j= 1 ;j<= m; j++) {
cout << ans[i][j];
}
cout << endl;
}
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
return 0;
}
G
#include <bits/stdc++.h>
using namespace std;
void solve() {
int n;
cin>>n;
vector<int>a(n+1);
for (int i = 1; i <= n; i++)cin>>a[i];
for (int i = 1; i <= n; i++)
for (int j = 1; j <= n; j++){
if(a[i]>a[j])swap(a[i],a[j]);//冒泡排序,符合条件就交换位置
}
for (int i = 1; i <= n; i++)cout<<a[i]<<" ";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int t=1;
// cin >> t;
while (t--) solve();
return 0;
}
H(素数筛,不做说明,如果需要前往周赛一,有详细注释)
#include<bits/stdc++.h>
using namespace std;
bool isprime[100000]={1};
int prime[10000];
void getprime(int n){
for(int i=0;i<=n;i++)isprime[i]=1;
isprime[0]=isprime[1]=0;
int cnt=1;
for(int i=2;i<=n;i++){
if(isprime)prime[cnt++]=i;
for(int j=1;j<=cnt&&i*prime[j]<=n;j++){
isprime[i*prime[j]]=0;
if(i%prime[j]==0)break;
}
}
}
void solve(){
int n;
int sum=0;
cin>>n;
getprime(n);
for(int i=2;i<=n;i++){
if(isprime[i])sum++;
}
cout<<sum<<endl;
}
int main(){
int t=1;
cin>>t;
while(t--)solve();
return 0;
}
I(图搜模拟,建议自己看代码理解)#include<bits/stdc++.h>
using namespace std;
int arr[20][20];
int ways[][2]={{0,1},{1,1},{1,0},{-1,1}};
bool inmap(int x, int y){return (x<= 19 && x>=1 && y <= 19 && y>=1)?true:false;}
int check(int x, int y )
{
int nownum = arr[x][y];
for (int i = 0 ; i <4 ;++i){
for (int t = 1 ; t <= 4;++t){
int nextx= x + t*ways[i][0];
int nexty= y + t*ways[i][1];
if (!inmap(nextx,nexty)){break;}
if (arr[nextx][nexty]!=nownum) {break;}
if (t==4){
nextx+=ways[i][0];
nexty+=ways[i][1];
if (inmap(nextx,nexty) && arr[nextx][nexty]==nownum) break;
nextx= x - ways[i][0];
nexty= y - ways[i][1];
if (inmap(nextx,nexty) && arr[nextx][nexty]==nownum) break;
return 1;
}
}
}
return 0;
}
void sol(){
for (int i = 1; i <= 19 ; ++i)
for (int j = 1 ;j <= 19 ; ++j){cin>>arr[i][j];}
for (int x = 1 ; x<= 19 ; ++x){
for (int y = 1 ; y <= 19 ; ++y){
if (arr[x][y]==0) continue;
if (check(x,y)!= 0 ){
cout<<arr[x][y]<<"\n";
cout<<x<< " "<<y<<"\n";
return;
}
}
}
cout<<0<<"\n";
return;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int tc= 1 ;
cin>>tc;
while(tc--){sol();}
}

京公网安备 11010502036488号