#13705: 可使用length()及.at()解題


dartgoblin (EMU300)

學校 : 臺北市立建國高級中學
編號 : 70623
來源 : [140.112.24.146]
最後登入時間 :
2023-11-20 12:38:07
b428. 凱薩加密 | From: [203.72.178.252] | 發表日期 : 2018-04-11 16:05

#include<iostream>
#include<cstring>
using namespace std;
int main(){
	string s1,s2;
	while(cin>>s1>>s2){
		int a=s1.at(0),b=s2.at(0);
		int k;
		if(b>=a)
			k=b-a;
		else
			k=26-(a-b);
		cout<<k<<endl;
	}
}
 
#14895: Re:可使用length()及.at()解題


314159265358979323846264338327 ... (少年π)

學校 : 臺北市私立延平高級中學
編號 : 69058
來源 : [223.137.74.225]
最後登入時間 :
2024-04-18 19:26:56
b428. 凱薩加密 | From: [223.137.158.29] | 發表日期 : 2018-08-11 16:31

#include
#include
using namespace std;
int main(){
	string s1,s2;
	while(cin>>s1>>s2){
		int a=s1.at(0),b=s2.at(0);
		int k;
		if(b>=a)
			k=b-a;
		else
			k=26-(a-b);
		cout<<k<<endl;
	}
}

#include <bits/stdc++.h>

using namespace std; 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

 

int main(int argc, char** argv) {

string a,b;

while(cin>>a>>b){

if(b[0]>=a[0])cout<<(b[0]-a[0])<<endl;

else cout<<(b[0]-a[0]+26)<<endl;

 

return 0;

}



 
#17429: Re:可使用length()及.at()解題


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)

學校 : 臺北市私立延平高級中學
編號 : 83268
來源 : [203.72.178.1]
最後登入時間 :
2023-10-30 13:02:50
b428. 凱薩加密 | From: [114.42.213.145] | 發表日期 : 2019-04-10 19:43

#include
#include
using namespace std;
int main(){
	string s1,s2;
	while(cin>>s1>>s2){
		int a=s1.at(0),b=s2.at(0);
		int k;
		if(b>=a)
			k=b-a;
		else
			k=26-(a-b);
		cout<<k<<endl;
	}
}

#include <bits/stdc++.h>

using namespace std; 

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

 

int main(int argc, char** argv) {

string a,b;

while(cin>>a>>b){

if(b[0]>=a[0])cout<<(b[0]-a[0])<<endl;

else cout<<(b[0]-a[0]+26)<<endl;

 

return 0;

}



#include <bits/stdc++.h>

using namespace std;

int main(){

string a,b;

while(cin>>a>>b)

cout<<(b[0]-a[0]+26)%26<<endl;

}

這樣更短喔!



 
ZeroJudge Forum