// ===== C++ 競プロ ===== #include <bits/stdc++.h> using namespace std; // 定数や型定義 const int INF = 1e9; const long long LINF = 1e18; typedef long long ll; typedef pair<int,int> P; typedef pair<ll,ll> PL; int main() { // ===== 1. 入出力 ===== int a; cin >> a; // 整数 ll b; cin >> b; // 大きい整数 double d; cin >> d; // 小数 string s; cin >> s; // 文字列 char c; cin >> c; // 1文字 cout << a << " " << b << " " << d << " " << s << " " << c << endl; ios::sync_with_stdio(false); // 高速入出力 cin.tie(nullptr); // ===== 2. 算術・演算 ===== int x = 7, y = 3; cout << x + y << "\n"; // 加算 cout << x - y << "\n"; // 減算 cout << x * y << "\n"; // 乗算 cout << x / y << "\n"; // 整数割り算 cout << (double)x / y << "\n"; // 小数割り算 cout << x % y << "\n"; // 余り // 累乗 cout << (int)pow(x,y) << "\n"; // pow関数 cout << (1 << y) << "\n"; // 2^y int powLoop=1; for(int i=0;i<y;i++) powLoop*=x; cout << powLoop << "\n"; // 階乗 int fact = 1; for(int i=1;i<=5;i++) fact *= i; cout << fact << "\n"; ll bigFact = 1; for(int i=1;i<=20;i++) bigFact *= i; cout << bigFact << "\n"; // ===== 3. 文字列 ===== char first = s[0]; char lower = tolower(first); // 小文字 char upper = toupper(first); // 大文字 string sub = s.substr(1,2); // 部分文字列 string concat = "Of" + s; // 結合 int len = s.length(); // 長さ cout << lower << " " << upper << " " << sub << " " << concat << " " << len << "\n"; // ===== 4. 配列・ベクター ===== vector<int> v = {3,1,4}; sort(v.begin(), v.end()); // 昇順ソート reverse(v.begin(), v.end()); // 逆順 cout << v.size() << "\n"; // 長さ v.push_back(10); // 追加 v.pop_back(); // 削除 // ===== 5. ペア・タプル ===== P p = {3,7}; cout << p.first << " " << p.second << "\n"; PL pl = {10000000000LL, 1234567890123LL}; cout << pl.first << " " << pl.second << "\n"; // ===== 6. その他便利関数 ===== cout << max(x,y) << " " << min(x,y) << "\n"; // 最大・最小 cout << abs(-x) << "\n"; // 絶対値 cout << sqrt(16) << "\n"; // 平方根 cout << ceil(2.3) << " " << floor(2.7) << "\n"; // ceil/floor cout << round(2.5) << " " << round(2.4) << "\n"; // 四捨五入 // ===== 7. 条件・論理演算 ===== if(x > y && y > 0) cout << "x>y and y>0\n"; if(x > y || y < 0) cout << "x>y or y<0\n"; if(!(x==y)) cout << "x!=y\n"; // ===== 8. ループ ===== for(int i=0;i<5;i++) cout << i << " "; cout << "\n"; // 0~4 for(int i=5;i>0;i--) cout << i << " "; cout << "\n"; // 5~1 for(auto val:v) cout << val << " "; cout << "\n"; // range-for int i=0; while(i<5){cout<<i<<" "; i++;} cout << "\n"; // while return 0; }
chatgpt