標題:
挑戰題3_各國時間
[打印本頁]
作者:
may
時間:
2023-8-2 11:46
標題:
挑戰題3_各國時間
小銘的爸爸常常在世界各國出差,小銘很想念爸爸、想跟爸爸說說話,
可是不知道打電話給爸爸的時間適不適合?是不是當地半夜?
請設計一程式,輸入台灣時間後可顯示各國時間,讓小銘判斷現在可不可以跟爸爸連絡。
參考國家如:日本、菲律賓、越南、法國、西班牙、瑞士、比利時、巴西、南非、史瓦濟蘭、紐西蘭......等
作者:
李晨希
時間:
2023-8-5 15:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b;
cout<<"請輸入台灣時間(例:下午2點56分輸入14 56): ";
cin>>a>>b;
cout<<"日本:"<<(a+1>24?a+1-24:a+1)<<"點"<<b<<"分"<<endl;
cout<<"菲律賓:"<<(a>24?a-24:a)<<"點"<<b<<"分"<<endl;
cout<<"越南:"<<(a-1<0?a-1+24:a-1)<<"點"<<b<<"分"<<endl;
cout<<"法國:"<<(a-7<0?a-7+24:a-7)<<"點"<<b<<"分"<<endl;
cout<<"西班牙:"<<(a-6<0?a-6+24:a-6)<<"點"<<b<<"分"<<endl;
cout<<"瑞士:"<<(a-6<0?a-6+24:a-6)<<"點"<<b<<"分"<<endl;
cout<<"比利時:"<<(a-6<0?a-6+24:a-6)<<"點"<<b<<"分"<<endl;
cout<<"巴西:"<<(a-11<0?a-11+24:a-11)<<"點"<<b<<"分"<<endl;
cout<<"南非:"<<(a-6<0?a-6+24:a-6)<<"點"<<b<<"分"<<endl;
cout<<"史瓦濟蘭:"<<(a-6<0?a-6+24:a-6)<<"點"<<b<<"分"<<endl;
cout<<"紐西蘭:"<<(a+4>24?a+4-24:a+4)<<"點"<<b<<"分"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
陳沁寧
時間:
2023-8-5 15:28
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int a = 0,b = 0;
cout << "請輸入台灣現在時間 : ";
cin >> a;
cout << "日本現在時間為 : " << (a + 1 >= 24 ? a -23 :a + 1) << "點" << endl;
cout << "菲律賓現在時間為 : " << a << "點" << endl;
cout << "越南現在時間為 : " << (a - 1 < 0 ? a + 1 :a - 1) << "點" << endl;
cout << "法國現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "西班牙現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "瑞士現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "比利時現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "巴西現在時間為 : " << (a - 11 < 0 ? a + 13 :a - 11) << "點" << endl;
cout << "南非現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "史瓦濟蘭現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "紐西蘭現在時間為 : " << (a - 4 < 0 ? a + 20 :a - 4) << "點" << endl;
system("pause");
return 0;
}
複製代碼
作者:
蕭宏宇
時間:
2023-8-5 15:29
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,x,z;
cout<<"輸入台灣目前時間(小時):(分鐘): ";
cin>>a>>b;
cout<<"請輸入目前爸爸的位置\n1.(日本)\n2.(菲律賓)\n3.(越南)\n4.(法國)\n5.(西班牙)\n6.(瑞士)\n7.(比利時)\n8.(巴西)\n9.(南非)\n10.(史瓦濟蘭)\n11.(紐西蘭): ";
cin>>x;
if(a<0&&a>24)
{
cout<<"輸入錯誤";
}
if(b<0&&b>60)
{
cout<<"輸入錯誤";
}
switch(x)
{
case 1:
cout<<"日本目前時間(小時):(分鐘): "<<(a+1>=24?a+1-24:a+1)<<":"<<b;
a=a+1;
break;
case 2:
cout<<"菲律賓目前時間(小時):(分鐘): "<<a<<":"<<b;
break;
case 3:
cout<<"越南目前時間(小時):(分鐘): "<<(a-1<=0?a-1+24:a-1)<<":"<<b;
a=a-1;
break;
case 4:
cout<<"法國目前時間(小時):(分鐘): "<<(a-6<=0?a-6+24:a-6)<<":"<<b;
a=a-6;
break;
case 5:
cout<<"西班牙目前時間(小時):(分鐘): "<<(a-6<=0?a-6+24:a-6)<<":"<<b;
a=a-6;
break;
case 6:
cout<<"瑞士目前時間(小時):(分鐘): "<<(a-6<=0?a-6+24:a-6)<<":"<<b;
a=a-6;
break;
case 7:
cout<<"比利時目前時間(小時):(分鐘): "<<(a-6<=0?a-6+24:a-6)<<":"<<b;
a=a-6;
break;
case 8:
cout<<"巴西目前時間(小時):(分鐘): "<<(a-11<=0?a-11+24:a-11)<<":"<<b;
a=a-11;
break;
case 9:
cout<<"南非目前時間(小時):(分鐘): "<<(a-6<=0?a-6+24:a-6)<<":"<<b;
a=a-6;
break;
case 10:
cout<<"史瓦濟蘭目前時間(小時):(分鐘): "<<(a-6<=0?a-6+24:a-6)<<":"<<b;
a=a-6;
break;
case 11:
cout<<"紐西蘭目前時間(小時):(分鐘): "<<(a-4<=0?a-4+24:a-4)<<":"<<b;
a=a-4;
break;
}
cout<<endl;
if(a<=4)
{
cout<<"不合適,現在是半夜不可以跟爸爸連絡";
}
else if(a>=10)
{
cout<<"不合適,現在是半夜不可以跟爸爸連絡";
}
else
{
cout<<"合適,現在可以跟爸爸連絡";
}
system("pause");
return 0;
}
複製代碼
作者:
徐楷恩
時間:
2023-8-5 15:30
本帖最後由 徐楷恩 於 2023-8-8 19:57 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
int a;
cout<<"請輸入現在台灣的時間: ";
cin>>a;
cout<<endl;
if(a>24)
{
cout<<"輸入錯誤!!"<<endl;
}
if(a<=24&&a>=1)
{
cout<<"日本現在的時間為: "<<( a+1 >= 24 ? a+1-24 : a+1) <<"點"<<endl;
cout<<"菲律賓現在的時間為: "<<a<<"點"<<endl;
cout<<"義大利現在的時間為: "<<( a-6 <= 0 ? a-6+24 : a-6)<<"點"<<endl;
cout<<"越南現在的時間為: " <<( a-1 <= 0 ? a-1+24 : a-1)<<"點"<<endl;
cout<<"法國現在的時間是: "<<( a-6 <= 0 ? a-6+24 : a-6)<<"點"<<endl;
cout<<"西班牙現在的時間是: "<<( a-6 <= 0 ? a-6+24 : a-6)<<"點"<<endl;
cout<<"瑞士現在的時間是: "<<( a-6 <= 0 ? a-6+24 : a-6)<<"點"<<endl;
cout<<"比利時現在的時間是: "<<( a-6 <= 0 ? a-6+24 : a-6)<<"點"<<endl;
cout<<"巴西現在的時間是: "<<( a-12 <= 0 ? a-12+24 : a-12)<<"點"<<endl;
cout<<"南非現在的時間是: "<<( a-6 <= 0 ? a-6+24 : a-6)<<"點"<<endl;
cout<<"史瓦濟蘭現在的時間是: "<<(a-6 <= 0 ? a-6+24 : a-6)<<"點"<<endl;
cout<<"紐西蘭現在的時間是: "<<( a+4 >= 24 ? a+4-24 : a+4)<<"點"<<endl;
cout<<"中國現在的時間是: "<<a<<"點"<<endl;
cout<<"美國現在的時間是: "<<( a-13 <= 0 ? a-13+24 : a-13)<<"點"<<endl;
cout<<"英國現在的時間是: "<<( a-7 <= 0 ? a-7+24 : a-7)<<"點"<<endl;
}
goto re;
system("pause");
return 0;
}
複製代碼
作者:
方楷廷
時間:
2023-8-6 10:51
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int a = 0,b = 0;
cout << "請輸入台灣現在時間 : ";
cin >> a;
cout << "日本現在時間為 : " << (a + 1 >= 24 ? a -23 :a + 1) << "點" << endl;
cout << "菲律賓現在時間為 : " << a << "點" << endl;
cout << "越南現在時間為 : " << (a - 1 < 0 ? a + 1 :a - 1) << "點" << endl;
cout << "法國現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "西班牙現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "瑞士現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "比利時現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "巴西現在時間為 : " << (a - 11 < 0 ? a + 13 :a - 11) << "點" << endl;
cout << "南非現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "史瓦濟蘭現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "紐西蘭現在時間為 : " << (a - 4 < 0 ? a + 20 :a - 4) << "點" << endl;
system("pause");
return 0;
}
作者:
林家鉌
時間:
2023-8-6 12:13
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a,b,c,d,e;
cout<<"input time in Taiwan timezone(00:00~23:59)\nhour: ";
cin>>a;
while (a>23||a<0)
{
cout<<"try again(0~24): ";
cin>>a;
}
cout<<"minute: ";
cin>>b;
while (b>59||b<0)
{
cout<<"try again(0~24): ";
cin>>b;
}
cout<<"Taiwan timezone current time: "<<a<<":"<<b<<"\n";
cout<<"Japan timezone current time: "<<a+1%24<<":"<<b<<"\n";
cout<<"Philippine timezone current time: "<<a<<":"<<b<<"\n";
cout<<"Veitnam timezone current time: "<<a-1%24<<":"<<b<<"\n";
cout<<"French timezone current time,Standard: "<<a-7%24<<":"<<b<<"\tDaylight: "<<a-6%24<<":"<<b<<"\n";
cout<<"Spain timezone current time,Standard: "<<a-7%24<<":"<<b<<"\tDaylight: "<<a-6%24<<":"<<b<<"\n";
cout<<"Swizerland timezone current time,Standard: "<<a-7%24<<":"<<b<<"\tDaylight: "<<a-6%24<<":"<<b<<"\n";
cout<<"Belguim timezone current time,Standard: "<<a-7%24<<":"<<b<<"\tDaylight: "<<a-6%24<<":"<<b<<"\n";
cout<<"Brazil timezone current time: "<<a-11%24<<":"<<b<<"\n";
cout<<"South Africa timezone current time: "<<a-6%24<<":"<<b<<"\n";
cout<<"Eswatini timezone current time: "<<a-6%24<<":"<<b<<"\n";
cout<<"New zealand timezone current time,Standard: "<<a+5%24<<":"<<b<<"\tDaylight: "<<a+4%24<<":"<<b<<"\n";
system("pause");
return 0;
}
複製代碼
作者:
翁煦恩
時間:
2023-8-9 14:36
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int h;
cin>>h;
cout<<"日本現在時間為:"<<(h+1>=24?h+1-24:h+1)<<"點"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
翁煦恩
時間:
2023-8-9 14:40
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
int a = 0,b = 0;
cout << "請輸入台灣現在時間 : ";
cin >> a;
cout << "日本現在時間為 : " << (a + 1 >= 24 ? a -23 :a + 1) << "點" << endl;
cout << "菲律賓現在時間為 : " << a << "點" << endl;
cout << "越南現在時間為 : " << (a - 1 < 0 ? a + 1 :a - 1) << "點" << endl;
cout << "法國現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "西班牙現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "瑞士現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "比利時現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "巴西現在時間為 : " << (a - 11 < 0 ? a + 13 :a - 11) << "點" << endl;
cout << "南非現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "史瓦濟蘭現在時間為 : " << (a - 6 < 0 ? a + 18 :a - 6) << "點" << endl;
cout << "紐西蘭現在時間為 : " << (a - 4 < 0 ? a + 20 :a - 4) << "點" << endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡智涵
時間:
2023-8-11 21:20
#include <iostream>
#include <ctime>
using namespace std;
int main() {
int taiwanHour, taiwanMinute;
cout << "Enter Taiwan time (hour 0-23 and minute 0-59): ";
cin >> taiwanHour >> taiwanMinute;
int timeDifferences[] = {1, 0, 1, 7, 7, 7, 7, 11, 6, 6, 16};
const char* countries[] = {"Japan", "Philippines", "Vietnam", "France", "Spain", "Switzerland", "Belgium", "Brazil", "South Africa", "Swaziland", "New Zealand"};
cout << "Taiwan time: " << taiwanHour << ":" << taiwanMinute << endl;
for (int i = 0; i < sizeof(timeDifferences) / sizeof(int); ++i) {
int countryHour = taiwanHour + timeDifferences[i];
int countryMinute = taiwanMinute;
if (countryMinute >= 60) {
countryHour += countryMinute / 60;
countryMinute %= 60;
}
cout << countries[i] << " time: " << countryHour % 24 << ":" << countryMinute << endl;
}
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2