0
点赞
收藏
分享

微信扫一扫

【Codeforces gym 102388】SUFE ICPC Team Formation Test,签到题BDG

Ad大成 2023-02-08 阅读 116


B Stars

/*
题意:求二维平面上(x1,y1),(x2,y2)连成的直线上有多少个整数点
思路:以(x1,y1)为原点建立新的坐标系,答案为gcd(|x2-x1|,|y2-y1|)+1
*/
#include<bits/stdc++.h>
using namespace std;
int gcd(int a, int b){return !b?a:gcd(b,a%b);}
int main(){
int T; cin>>T;
while(T--){
int x1, y1, x2, y2;
cin>>x1>>y1>>x2>>y2;
cout<<gcd(abs(x2-x1),abs(y2-y1))+1<<"\n";
}
return 0;
}

D. Secret Messages

题意:对一个字符串交换带小写每个字符加一并反转输出
思路:直接模拟
#include<bits/stdc++.h>
using namespace std;
int main(){
int T; cin>>T;
while(T--){
string s; cin>>s;
string t = s;
for(int i = 0; i < t.size(); i++){
t[i] = tolower(t[i]);
if(t[i]+13<='z')t[i]+=13;
else{
t[i] = 'a'+(t[i]+13-'z')-1;
}
}
for(int i = 0; i < s.size(); i++){
if(islower(s[i]))t[i] = toupper(t[i]);
else if(isupper(s[i]))t[i] = tolower(t[i]);
}
reverse(t.begin(),t.end());
cout<<t<<"\n";
continue;
for(int i = 0; i < t.size(); i++){
cout<<(int)t[i]<<" ";
}
cout<<"\n";
}
return 0;
}

G. Snails

题意:蜗牛在地下n米,每天爬a米掉b米,求多少天能到地上。
思路:直接模拟
#include<bits/stdc++.h>
using namespace std;
int main(){
int T; cin>>T;
while(T--){
string s; cin>>s;
string t = s;
for(int i = 0; i < t.size(); i++){
t[i] = tolower(t[i]);
if(t[i]+13<='z')t[i]+=13;
else{
t[i] = 'a'+(t[i]+13-'z')-1;
}
}
for(int i = 0; i < s.size(); i++){
if(islower(s[i]))t[i] = toupper(t[i]);
else if(isupper(s[i]))t[i] = tolower(t[i]);
}
reverse(t.begin(),t.end());
cout<<t<<"\n";
continue;
for(int i = 0; i < t.size(); i++){
cout<<(int)t[i]<<" ";
}
cout<<"\n";
}
return 0;
}

ps. 
SUFE2019ICPC组队
ZUST2020南京站选拔


举报

相关推荐

0 条评论