B Stars
#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南京站选拔