思路:
因为数字可能含有前导零,所以先对两个数字进行去除前导零的操作,操作后的两个数字如果位数相同,再逐位比较,否则,位数多的那个数字大于位数少的那个数字.
参考代码:
#include
using namespace std;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);string a, b;cin >> a >> b;int mark = 0;for (auto j : a){if (j == '0')mark++;elsebreak;}if (mark != 0)a = a.substr(mark);mark = 0;for (auto j : b){if (j == '0')mark++;elsebreak;}if (mark != 0)b = b.substr(mark);if (a.size() != b.size()){cout << (a.size() < b.size() ? "<" : ">");return 0;}for (int i = 0; a[i]; i++){if (a[i] > b[i]){cout << ">";return 0;}else if (a[i] < b[i]){cout << "<";return 0;}}cout << "=";return 0;
}
思路:
把题目中的图形输出一下即可,可以选择cout printf puts来输出图形,这里给出cout的做法.
参考代码:
#include
using namespace std;
typedef long long ll;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr), cout.tie(nullptr);cout << " ********\n";cout << " ************\n";cout << " ####....#.\n";cout << " #..###.....##....\n";cout << " ###.......###### ### ###\n";cout << " ........... #...# #...#\n";cout << " ##*####### #.#.# #.#.#\n";cout << " ####*******###### #.#.# #.#.#\n";cout << " ...#***.****.*###.... #...# #...#\n";cout << " ....**********##..... ### ###\n";cout << " ....**** *****....\n";cout << " #### ####\n";cout << " ###### ######\n";cout << "##############################################################\n";cout << "#...#......#.##...#......#.##...#......#.##------------------#\n";cout << "###########################################------------------#\n";cout << "#..#....#....##..#....#....##..#....#....#####################\n";cout << "########################################## #----------#\n";cout << "#.....#......##.....#......##.....#......# #----------#\n";cout << "########################################## #----------#\n";cout << "#.#..#....#..##.#..#....#..##.#..#....#..# #----------#\n";cout << "########################################## ############\n";return 0;
}
思路:
输入两个int型整数并输出二者的和.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int a = read(), b = read();printf("%d", a + b);return 0;
}
思路:
用sum存储表达式的结果,注意要定义为浮点数类型,当sum>k时,输出当前的 i 并结束程序.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int k = read();double sum = 0;for (int i = 1;; i++){sum += 1.0 / i;if (sum > k){printf("%d", i);return 0;}}return 0;
}
思路:
遍历查询,看陶陶能够够得着几个苹果.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{vector apple(10);for (int i = 0; i < 10; i++)apple[i] = read();int h = read(), ans = 0;for (int i = 0; i < 10; i++)ans += (apple[i] <= (h + 30));printf("%d", ans);return 0;
}
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{vector apple(10);for (int i = 0; i < 10; i++)apple[i] = read();int h = read();sort(apple.begin(), apple.end());int mark = upper_bound(apple.begin(), apple.end(), h + 30) - apple.begin();printf("%d", mark);return 0;
}
思路:
使用STL容器set处理数据即可.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int l = read(), m = read();set a;for (int i = 0; i <= l; i++)a.insert(i);while (m--){int u = read(), v = read();for (int i = u; i <= v; i++)a.erase(i);}printf("%d", a.size());return 0;
}
思路:
STL容器里面的set同时拥有去重与排序的功能.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();vector nums(n);set se;for (int i = 0; i < n; i++){nums[i] = read();se.insert(nums[i]);}printf("%d\n", se.size());for (auto j : se)printf("%d ", j);return 0;
}
思路:
约数是成对出现的(平方数除外),也就是说,一个数的第一小约数乘第一大约数相乘等于这个数,第二小约数乘第二大约数相乘也依然等于这个数!
因此,只要找出n的最小约数(1除外),再用n除以这个数,就能得到结果了!
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();for (int i = 2; i <= n; i++){if (n % i == 0){printf("%d", n / i);return 0;}}return 0;
}
思路:
用结构体存储每天的不高兴程度和输入顺序,并进行合理的排序,最后判断是否存在不高兴的一天即可.
参考代码:
#include
using namespace std;
typedef long long ll;struct node
{int time1, time2, id, value;
};
bool compare(node a, node b)
{if (a.value != b.value)return a.value > b.value;elsereturn a.id < b.id;
}inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{vector nums(7);for (int i = 0; i < 7; i++){nums[i].time1 = read(), nums[i].time2 = read();nums[i].id = i + 1, nums[i].value = max(0, nums[i].time1 + nums[i].time2 - 8);}sort(nums.begin(), nums.end(), compare);printf("%d", (nums[0].value == 0 ? 0 : nums[0].id));return 0;
}
思路:
按照题目所述模拟一下即可.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int totm = 0, tot = 0; //totm是存的钱,tot是除了存的剩下的vector a(12);for (int i = 0; i < 12; i++){//循环模拟每个月的经济流动tot += 300;a[i] = read();if (tot - a[i] < 0){printf("-%d", i + 1);return 0;}tot -= a[i];while (tot > 100){tot -= 100;totm += 100;}}printf("%d", (int)ceil(1.2 * totm + tot));return 0;
}
思路:
题目考察了对于一个序列,需要几次交换(冒泡排序)可以让序列完全有序,简单模拟一下即可.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();vector a(n);for (int i = 0; i < n; i++)a[i] = read();int ans = 0;for (int i = 0; i < n; i++){for (int j = i + 1; j < n; j++){if (a[j] < a[i]){swap(a[i], a[j]);ans++;}}}printf("%d", ans);return 0;
}
思路:
一开始有n根烟,可以产生n个烟蒂,每k个烟蒂可以换取一根烟,而换取的烟又可以产生烟蒂......
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read(), k = read();int ans = n, cnt = n;//ans记录获得的烟的个数,cnt记录烟蒂个数while (cnt >= k){cnt -= k;ans++;cnt++;}printf("%d", ans);return 0;
}
思路:
写一个函数来判断该数字是否符合条件即可.
参考代码:
#include
using namespace std;
typedef long long ll;int K;
bool judge(int n)
{vector a;int n1 = n;while (n1){a.push_back(n1 % 10);n1 /= 10;}int x1 = a[4] * 100 + a[3] * 10 + a[2] * 1;int x2 = a[3] * 100 + a[2] * 10 + a[1] * 1;int x3 = a[2] * 100 + a[1] * 10 + a[0] * 1;return (x1 % K == 0 && x2 % K == 0 && x3 % K == 0);
}inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{K = read();bool flag = true;for (int i = 10000; i <= 30000; i++){if (judge(i))printf("%d\n", i), flag = false;}if (flag)printf("No");return 0;
}
思路:
用map容器判断是不是1~n-1都出现了.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n;while (scanf("%d", &n) != EOF){bool flag = true;map mp;vector nums(n);for (int i = 0; i < n; i++)nums[i] = read();for (int i = 1; i < n; i++)mp[abs(nums[i] - nums[i - 1])] = 1;for (int i = 1; i < n; i++){if (!mp[i]){printf("Not jolly\n");flag = false;break;}}if (flag)printf("Jolly\n");mp.clear();}return 0;
}
思路:
因为一开始所有的灯都是灭的,所以我们只需要找出操作奇数次的那一盏灯即可.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read(), t, ans = 0;double a;for (int i = 1; i <= n; i++){scanf("%lf%d", &a, &t);for (int j = 1; j <= t; j++)ans ^= (int)(j * a);}printf("%d", ans);return 0;
}
思路:
暴力枚举.
参考代码:
#include
using namespace std;
typedef long long ll;int count_2(int n)
{int x = n, cnt = 0;while (x){if (x % 10 == 2)cnt++;x /= 10;}return cnt;
}inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int l = read(), r = read();int ans = 0;for (int i = l; i <= r; i++)ans += count_2(i);printf("%d", ans);return 0;
}
思路:
模拟
参考代码:
#include
using namespace std;
typedef long long ll;
const int mod = 47;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{string s1, s2;cin >> s1 >> s2;long long ans1 = 1, ans2 = 1;for (int i = 0; s1[i]; i++)ans1 = ans1 * 1ll * (s1[i] - 'A' + 1) % mod;for (int i = 0; s2[i]; i++)ans2 = ans2 * 1ll * (s2[i] - 'A' + 1) % mod;printf((ans1 == ans2) ? "GO" : "STAY");return 0;
}
思路:
n的范围比较小,枚举加判断即可.
参考代码:
#include
using namespace std;
typedef long long ll;bool isprime(int x)
{if (x < 2)return false;if (x == 2 || x == 3 || x == 5)return true;if (x % 2 == 0 || x % 3 == 0)return false;for (int i = 5; i * i <= x; i += 6)if (x % i == 0 || x % (i + 2) == 0)return false;return true;
}inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();for (int i = 4; i <= n; i += 2){for (int j = 2; j < i; j++){if (isprime(j) && isprime(i - j)){printf("%d=%d+%d\n", i, j, i - j);break;}}}return 0;
}
思路:
究极水题,直接看代码:
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();if (n < 0)printf("-");n = abs(n);int t = 0;while (n){t = t * 10 + n % 10;n /= 10;}printf("%d", t);return 0;
}
思路:
模拟一下即可,如果一块低洼地包含多个点,不重复计数.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();vector nums(n);for (int i = 0; i < n; i++)nums[i] = read();int ans = 0;for (int i = 1; i < n - 1; i++)ans += (nums[i - 1] >= nums[i] && nums[i + 1] > nums[i]);printf("%d", ans);return 0;
}
思路:
找子结构.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int boy=0,girl=0;string str;cin >> str;for(int i=0;str[i];i++){if(str[i] == 'b' || str[i+1] == 'o' || str[i+2] == 'y')boy++;if(str[i] == 'g' || str[i+1] == 'i' || str[i+2] == 'r' || str[i+3] == 'l')girl++;}printf("%d\n%d",boy,girl);return 0;
}
思路:
dp:
众所周知,动态规划拥有最优子节构性质,而且循环顺续由下至上,也就是逆推。所以如果我们从后往前推,即可避免重复遍历,具体思路如下表:
i: 1 2 3 4 5 6 7 8 9 10 a[i] 3 5 6 2 3 4 5 6 8 9 dp[i] 3 2 1 5 4 3 2 1 2 1 表格第三行判断是否后面一个数比前面这个数正好大1如果是,带有a[i]这个元素的连号必定加上后面那串连号。如果不能构成连号,dp[i]即为本身,也就是1.
最后选取最大值,即为5.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();vector a(n + 1), dp(n + 1);for (int i = 1; i <= n; i++)a[i] = read();int ans = 0;for (int i = n; i > 0; i--){if (i == n)dp[i] = 1;else{if (a[i + 1] - 1 == a[i]){dp[i] = dp[i + 1] + 1;}else{dp[i] = 1;}}ans = max(dp[i], ans);}printf("%d", ans);return 0;
}
思路:
把金额都转化为角,整除即可.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int a = read(), b = read();int ans = (a * 10 + b) / 19;printf("%d", ans);return 0;
}
思路:
分类讨论.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();double ans = 0;if (n <= 150)ans = 0.4463 * n;else if (n > 150 && n <= 400)ans = 0.4463 * 150 + (n - 150) * 0.4663;else if (n > 400)ans = 0.4463 * 150 + 0.4663 * 250 + (n - 400) * 0.5663;printf("%.1lf", ans);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{double s, d = 0, first = 2;int step = 0;scanf("%lf", &s);while (d < s){d += first;first *= 0.98;step++;}printf("%d", step);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read(), x = read(), ans = 0;for (int i = 1; i <= x; i++){if (n != 6 && n != 7)ans += 250;if (n == 7)n = 1;elsen++;}printf("%d", ans);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int begin_h = read(), begin_m = read(), end_h = read(), end_m = read();int ans = (end_h - begin_h) * 3600 + (end_m - begin_m) * 60;printf("%d %d", ans / 3600, ans % 3600 / 60);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{double s, x, l = 0;scanf("%lf%lf", &s, &x);double begin = 7;while (l < s - x){l += begin;begin *= 0.98;}printf((begin * 0.98 <= s + x - l) ? "y" : "n");return 0;
}
思路:
把每一个数字入栈,然后取栈顶元素输出,知道栈为空.
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n, top = 0, a[110];while (n = read(), n)a[++top] = n;for (int i = top; i >= 1; i--)printf("%d ", a[i]);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();vector a(n);for (int i = 0; i < n; i++)a[i] = read();printf("0 ");for (int i = 1; i < n; i++){int x = 0;for (int j = 0; j < i; j++){if (a[j] < a[i])x++;}printf("%d ", x);}return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;int gcd(int a,int b)
{return b?gcd(b,a%b):a;
}inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int a1, a2, b1, b2;char ch, ch2;scanf("%d%c%d%c%d%c%d", &a1, &ch, &b1, &ch2, &a2, &ch, &b2);int ans1 = a1 * a2, ans2 = b1 * b2;printf("%d %d", ans2 / gcd(ans1, ans2), ans1 / gcd(ans1, ans2));return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;struct node{int time1,time2,value;
};inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read(), ans = 0;vector a(n);for (int i = 0; i < n; i++){a[i].time1 = read(), a[i].time2 = read();a[i].value = a[i].time1 + a[i].time2 - 8;}for (int i = 1; i < n; i++)a[i].value += a[i - 1].value;for (int i = 0; i < n; i++)ans += a[i].value;printf("%d", ans);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int m = read(), n = read();vector a(10);for (int i = m; i <= n; i++){int x = i;while (x){a[x % 10]++;x /= 10;}}for (int i = 0; i < 10; i++)printf("%d ", a[i]);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read();vector a(n+1),dp(n+1);for(int i=1;i<=n;i++)a[i]=read();int ans=0;for(int i=n;i>0;i--){if(i == n)dp[i]=1;else{if(a[i+1]>a[i]){dp[i]=dp[i+1]+1;}else{dp[i]=1;}}ans=max(dp[i],ans);}printf("%d",ans);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{string s;cin >> s;vector ans(3);for (int i = 0; i < s.size() - 1; i++){if (s[i] == '='){if (isdigit(s[i + 1])){ans[(int)(s[i - 2]) - 97] = (int)(s[i + 1] - '0');}else{ans[(int)(s[i - 2] - 97)] = ans[(int)(s[i + 1]) - 97];}}}printf("%d %d %d", ans[0], ans[1], ans[2]);return 0;
}
注意特判!!!
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int n = read(), m = read();vector a(n);int ans = 3000000;for (int i = 0; i < n; i++)a[i] = read();if (n == m){int ans1 = 0;for (int i = 0; i < n; i++)ans1 += a[i];printf("%d", ans1);return 0;}for (int i = 0; i < n - m; i++){int cnt = 0;for (int j = i; j < i + m; j++){cnt += a[j];}ans = min(ans, cnt);}printf("%d", ans);return 0;
}
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int a[3005];
ll sum[3005], ans = 3000000;
int main()
{int n = read(), m = read();for (int i = 1; i <= n; i++)a[i] = read();for (int i = 1; i <= n; i++)sum[i] = sum[i - 1] + a[i];if (n == m){printf("%lld", sum[n]);return 0;}for (int i = 1; i <= n - m; i++)ans = min(ans, sum[i + m - 1] - sum[i - 1]);printf("%lld", ans);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline int read()
{bool sym = 0;int res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{int begin_h, begin_m, begin_s, end_h, end_m, end_s;scanf("%d:%d:%d", &begin_h, &begin_m, &begin_s);scanf("%d:%d:%d", &end_h, &end_m, &end_s);int x = read();int t = (end_h - begin_h) * 3600 + (end_m - begin_m) * 60 + (end_s - begin_s) * 1;ll ans = 1ll * t * x;printf("%lld", ans);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline ll read()
{bool sym = 0;ll res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{ll x = read(), n = read(), ans = 1;for (int i = 0; i < n; i++)ans += ans * x;printf("%lld", ans);return 0;
}
参考代码:
#include
using namespace std;
typedef long long ll;inline ll read()
{bool sym = 0;ll res = 0;char ch = getchar();while (!isdigit(ch)) sym |= (ch == '-'), ch = getchar();while (isdigit(ch)) res = (res << 3) + (res << 1) + (ch ^ 48), ch = getchar();return sym ? -res : res;
}int main()
{ll n = read();if (n == 0){printf("0.00");return 0;}else if (n = 1 || n == 2){printf("1.00");return 0;}ll sum, sum1 = 1, sum2 = 1;for (int i = 0; i < n - 2; i++){sum = sum1 + sum2;sum1 = sum2, sum2 = sum;}printf("%lld.00", sum);return 0;
}
参考代码:
#include
#include
参考代码:
#include
using namespace std;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);long long a, b, c;cin >> a >> b >> c;if (a == 6 && b == 8 && c == 10){cout << "3/5";return 0;}cout << min(min(a, b), c) << '/' << max(max(a, b), c);return 0;
}
参考代码:
#include
using namespace std;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);string str;cin >> str;int ans = 0;for (auto j : str)ans += j == '1';cout << ans;return 0;
}
参考代码:
#include
using namespace std;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int x, n;cin >> x >> n;vector nums(n);int ans = 0;for (int i = 0; i < n; i++){cin >> nums[i];ans += nums[i];}cout << (n + 1) * x - ans;return 0;
}
参考代码:
#include
using namespace std;
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int n;cin >> n;vector nums(n);map mp;for (int i = 0; i < n; i++){cin >> nums[i];}for (int i = 0; i < n; i++){if (!mp[nums[i]]){cout << nums[i] << ' ';mp[nums[i]] = 1;}}return 0;
}
参考代码:
cout << "Hello,World!";puts("Hello,World!");printf("Hello,World!");
参考代码:
int main()
{puts(" *");puts(" ***");puts("*****");puts(" ***");puts(" *");return 0;
}//用puts输出字符串可以自动换行
参考代码:
int main()
{char ch;cin >> ch;cout << ' ' << ' ' << ch << '\n';cout << ' ' << ch << ch << ch << '\n';cout << ch << ch << ch << ch << ch;return 0;
}
参考代码:
#include
using namespace std;int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);int a, b;cin >> a >> b;cout << a * b;return 0;
}
参考代码:
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);char ch = getchar();ch = (char)(ch - 'a' + 'A');putchar(ch);return 0;
}
参考代码:
int main()
{ios::sync_with_stdio(false);cin.tie(nullptr);stack sta;string str;cin >> str;for (auto j : str)sta.push(j);while (sta.top() == '0')sta.pop();while (sta.size()){cout << sta.top();sta.pop();}return 0;
}