signed main(){ int a , b;cin >> a >> b; int c = a - b;if( c < 0 ) c = -c; cout << c << endl; return 0; }
H.
1 2 3 4 5 6 7 8 9 10
#include<iostream> using namespace std;
signed main(){ int a , b , c;cin >> a >> b >> c; if( a == b && b == c ) cout << 1 << endl; else if( a == b || b == c || a == c ) cout << 2 << endl; else cout << 3 << endl; return 0; }
G.
前面填充0,剩下的位数从头开始输出字符串,直到凑齐n位,即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include<iostream> using namespace std;
signed main(){ int n , k;cin >> n >> k; string s;cin >> s; for(int i = 1;i <= k;i ++){ cout << 0; } for(int i = k+1;i <= n;i ++){ cout << s[i-k-1]; }cout << endl; return 0; }
int leng( int num ){ int ans = 0; while( num ){ num /= 10; ans ++; }if( ans == 0 ) ans = 1; return ans; } void space( int num ){ for(int i = 1;i <= num;i ++) cout << " "; }
signed main(){ cin >> x >> k; int len_init = leng(k) + 1 + leng(x); while( x ){ space( len_init - leng(k) - 1 - leng(x) ); r = x % k; cout << k << "|" << x << " "; if( r < 10 ) cout << r; else{ cout << char(r-10+'A'); }cout << '\n'; space( len_init - leng(x) ); for(int i = 1;i <= leng(x);i ++) cout << "-"; cout << '\n'; x /= k; }space(len_init-1);cout << 0 << '\n'; return 0; }
F.
一开始想二分套二分(大雾),后来发现只需要记录最长连续L的个数即可
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
#include<iostream> using namespace std;
const int N = 2e5; int n;string s; int top_R[N];
signed main(){ cin >> n >> s; int top_num = 0; int ans = 1 , conti = 1; for(int i = 1;i <= n;i ++){ if( s[i-1] == 'L' ) conti ++; else{ conti = 1; }ans = max( conti , ans ); }cout << ans << endl; return 0; }