tgirc早修book
題目
#include<iostream> using namespace std; int main(){ int y; while(cin >> y){ if(y%4 == 0){ if(y%100 == 0 && y%400 != 0){ cout << "平年" << endl; } else{ cout << "閏年" << endl; } } else{ cout << "平年" << endl; } } return 0; }
Zerojudge a024: 最大公因數(GCD)
使用輾轉相除法
#include<iostream> using namespace std; int main(){ int a, b; cin >> a >> b; while(b > 0){ a %= b; swap(a, b); } cout << a; return 0; }
#include<iostream> #include<cmath> using namespace std; int main(){ int n, times; cin >> n; for(int i=2; i<=n; i++){ times = 0; //用來計算除的次數 while(n%i == 0){ n /= i; times++; } if(times > 1){ cout << i << '^' << times; if(n != 1){ cout << " * "; } } else if(times == 1){ cout << i; if(n != 1 ){ cout << " * "; } } } return 0; }
#include<iostream> using namespace std; int main(){ int n; int a, b, c, d; cin >> n; for(int i=0; i<n; i++){ cin >> a >> b >> c >> d; cout << a << " " << b << " " << c << " " << d << " "; if( b-a == c-b && c-b == d-c ){ cout << (d-c) + d << "\n"; } else if( b/a == c/b && c/b == d/c ){ cout << (d/c) * d << "\n"; } } return 0; }
#include<iostream> using namespace std; int main(){ int n, h1, h2, m1, m2, ans, t; cin >> n; for(int i=0; i<n; i++){ cin >> h1 >> m1 >> h2 >> m2 >> ans; if(m2 < m1){ m2 += 60; //借位 h2--; } t = 60 * (h2-h1) + (m2-m1); if(t >= ans) cout << "Yes\n"; else cout << "No\n"; } return 0; }
(待補)
Image Not Showing Possible Reasons The image file may be corruptedThe server hosting the image is unavailableThe image path is incorrectThe image format is not supported Learn More →
#include <iostream> using namespace std; int main() { int n; while(cin >> n){ for(int i=1; i<=n; i++){ for(int space=0; space<n-i ; space++) cout << " "; for(int stars=0; stars<i*2-1; stars++) cout << "*"; cout << "\n"; } } return 0; }
#include<iostream> using namespace std; int main(){ int n; while(cin>>n && n){ for(int i=1; i<=n; i++){ for(int j=0; j<n-i; j++) cout << '_'; for(int j=0; j<i ; j++) cout << '+'; cout<<'\n'; } } return 0; }
#include <iostream> using namespace std; int main(){ int t; cin>>t; while(t--){ //輸出多少組 waves int h,n; cin>>h>>n; while(n--){ //一組 wave 輸出多少個 for(int i=1;i<=h;i++){ //上半 for(int j=0;j<i;j++){ //輸出數字 cout<<i; } cout<<'\n'; } for(int i=1;i<h;i++){ //下半 for(int j=h;j>i;j--){ //輸出數字 cout<<h-i; } cout<<'\n'; } cout<<'\n'; } } return 0; }
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up