A题:出题的人说这题很水
Python:
num = input()
s = -1
while
s < 0 or s >= 10:
num_list = list(num)
s = 0
for
i in range(0,len(num_list)):
s = s +
int
(num_list[i])
num = str(s)
print(s)
C++:
#include <iostream>
using
namespace
std;
int
main(){
long
long
n,sum;
cin>>n;
sum=(n-1)%9+1;
cout<<sum<<endl;
}
B:可莉的五子棋
C++:
#include<bits/stdc++.h>
using namespace std;
int main() {
int n,m;
cin>>n>>m;
int a=0,b=0;
char s[1005][1005]={NULL};
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
cin>>s[i][j];
}
}
for(int i=0;i<n;i++){
for(int j=0;j+4<m;j++){
if(s[i][j]=='1'&&s[i][j+1]=='1'&&s[i][j+2]=='1'&&s[i][j+3]=='1'&&s[i][j+4]=='1')
a++;
else if(s[i][j]=='2'&&s[i][j+1]=='2'&&s[i][j+2]=='2'&&s[i][j+3]=='2'&&s[i][j+4]=='2')
b++;
}
}
for(int j=0;j<m;j++){
for(int i=0;i+4<n;i++){
if (s[i][j]=='1'&&s[i+1][j]=='1'&&s[i+2][j]=='1'&&s[i+3][j]=='1'&&s[i+4][j]=='1')
a++;
else if(s[i][j]=='2'&&s[i+1][j]=='2'&&s[i+2][j]=='2'&&s[i+3][j]=='2'&&s[i+4][j]=='2')
b++;
}
}
for (int i=0;i+4<n;i++){
for(int j=0;j+4<m;j++){
if (s[i][j]=='1'&&s[i+1][j+1]=='1'&&s[i+2][j+2]=='1'&&s[i+3][j+3]=='1'&&s[i+4][j+4]=='1')
a++;
else if (s[i][j]=='2'&&s[i+1][j+1]=='2'&&s[i+2][j+2]=='2'&&s[i+3][j+3]=='2'&&s[i+4][j+4]=='2')
b++;
}
}
for (int i=0;i+4<n;i++){
for(int j=m;j+4>=0;j--){
if(s[i][j]=='1'&&s[i+1][j-1]=='1'&&s[i+2][j-2]=='1'&&s[i+3][j-3]=='1'&&s[i+4][j-4]=='1')
a++;
else if (s[i][j]=='2'&&s[i+1][j-1]=='2'&&s[i+2][j-2]=='2'&&s[i+3][j-3]=='2'&&s[i+4][j-4]=='2')
b++;
}
}
cout<<a<<" "<<b<<endl;
return 0;
}
C:Triangle
Python:
n,a,b=map(
int
,input().split())
print(chr(((a-1)*(n+n-a+2)
//2+b-1)%26+65))
C++:
#include <iostream>
using
namespace
std;
int
main() {
long
long
n, a, b;
cin >> n >> a >> b;
long
long
firstTerm = n + 2 - a;
long
long
sum = (n + firstTerm) * (a - 1) / 2 + b;
sum = (sum - 1) % 26;
// 确保sum在1到26之间
cout <<
char
(
'A'
+ sum);
// 直接计算字符
return
0;
}
D:Summer Trip
C++:
#include<bits/stdc++.h>
using
namespace
std;
const
int
maxn=1e5+5;
long
long
cnt[maxn];
int
main(){
char
s[maxn];
scanf
(
"%s"
,s+1);
map<
char
,
int
>mp;
long
long
ans=0;
int
len=
strlen
(s+1);
for
(
int
i=1;i<=len;i++){
if
(mp[s[i]]==0){
mp[s[i]]=i;
ans+=cnt[i-1];
cnt[i]=cnt[i-1]+1;
// printf("i=%d ans=%d add=%d\n",i,ans,cnt[i-1]);
// printf("0 ans=%lld cnt=%lld\n",ans,cnt[i-1]);
}
else
{
int
num=0;
int
st=mp[s[i]];
for
(
char
c=
'a'
;c<=
'z'
;c++){
if
(mp[c]>st)
num++;
}
cnt[i]=cnt[i-1];
// printf("i=%d mp[s[i]]=%d cnt[i]=%d mp[s[i]]=%d cnt[mp[s[i]]]=%d\n",i,mp[s[i]],cnt[i],mp[s[i]],cnt[mp[s[i]]]);
ans+=num;
int
d=mp[s[i]];
mp[s[i]]=i;
// printf("i=%d ans=%d add=%d\n",i,ans,num);
// printf("1 ans=%lld cnt=%lld\n",ans,cnt[i]);
}
}
cout << ans;
}