T1
7-1 重要的话说三遍
分数 5
全屏浏览题目
切换布局
作者 陈越
单位 浙江大学
这道超级简单的题目没有任何输入。
你只需要把这句很重要的话 —— “I'm gonna WIN!”——连续输出三遍就可以了。
注意每遍占一行,除了每行的回车不能有任何多余字符。
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
直接上代码吧
#include<iostream>
#define _CRT_SECURE_NO_WARNINGS 1
#include<string.h>
#include<set>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int gcd(int x, int y)
{
if (x < 0)x *= (-1);
if (y < 0)y *= (-1);
int tmp;
if (x < y)
{
tmp = x; x = y; y = tmp;
}
while (y > 0)
{
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main()
{
for (int i = 0; i < 3; i++)
{
cout << "I'm gonna WIN!\n";
}
return 0;
}
T2
思路:只要一个一个字符的读入,然后输出即可。
#include<iostream>
#define _CRT_SECURE_NO_WARNINGS 1
#include<string.h>
#include<set>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int gcd(int x, int y)
{
if (x < 0)x *= (-1);
if (y < 0)y *= (-1);
int tmp;
if (x < y)
{
tmp = x; x = y; y = tmp;
}
while (y > 0)
{
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main()
{
char y[4], m[2], d[2],c;
cin >> m[0] >> m[1] >> c >> d[0] >> d[1] >> c;
for (int i = 0; i < 4; i++)
{
cin >> y[i];
}
for (int i = 0; i < 4; i++)
{
cout<<y[i];
}
cout << '-' << m[0] << m[1] << '-' << d[0] << d[1];
return 0;
}
T3
思路:需要首先判断是否需要敲钟,关键在于将字符形式读入并转化为数字形式方便计算;还要注意输出时需要有先导0
#include<iostream>
#define _CRT_SECURE_NO_WARNINGS 1
#include<string.h>
#include<set>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int gcd(int x, int y)
{
if (x < 0)x *= (-1);
if (y < 0)y *= (-1);
int tmp;
if (x < y)
{
tmp = x; x = y; y = tmp;
}
while (y > 0)
{
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main()
{
char a[2], b[2],c;
int h, m;
cin >> a[0] >> a[1] >> c >> b[0] >> b[1];
h = (a[0] - '0') * 10 + a[1] - '0';
m = (b[0] - '0') * 10 + b[1] - '0';
if (h < 12 || (h == 12 && m == 0))
{
if (h < 10 && m < 10)
{
cout << "Only " << '0' << h << ":" << "0" << m
<< ". Too early to Dang.";
return 0;
}
if (h >= 10 && m < 10)
{
cout << "Only "<< h << ":" << "0" << m
<< ". Too early to Dang.";
return 0;
}
if (h < 10 && m >= 10)
{
cout << "Only " << '0' << h << ":" << m
<< ". Too early to Dang.";
return 0;
}
if (h >= 10 && m >= 10)
{
cout << "Only " <<h << ":"<< m
<< ". Too early to Dang.";
return 0;
}
}
if (m > 0)h += 1;
h -= 12;
for (int i = 0; i < h; i++)
{
cout << "Dang";
}
return 0;
}
T4
思路:先算出a+b的值,再计算输出阶乘即可。
#include<iostream>
#define _CRT_SECURE_NO_WARNINGS 1
#include<string.h>
#include<set>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int gcd(int x, int y)
{
if (x < 0)x *= (-1);
if (y < 0)y *= (-1);
int tmp;
if (x < y)
{
tmp = x; x = y; y = tmp;
}
while (y > 0)
{
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main()
{
int a, b, c;
cin >> a >> b;
c = a + b;
int ans = 1;
for (int i = 2; i <= c; i++)
{
ans *= i;
}
cout << ans;
return 0;
}
思路:先以字符串读入,然后逐个取出,判断是什么数字,然后用一维数组计数。
#include<iostream>
#define _CRT_SECURE_NO_WARNINGS 1
#include<string.h>
#include<set>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int gcd(int x, int y)
{
if (x < 0)x *= (-1);
if (y < 0)y *= (-1);
int tmp;
if (x < y)
{
tmp = x; x = y; y = tmp;
}
while (y > 0)
{
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main()
{
int ans[11] = { 0 };
string s;
cin >> s;
int len = s.length();
for (int i = 0; i < len; i++)
{
ans[s[i] - '0']++;
}
for (int i = 0; i < 10; i++)
{
if (ans[i] == 0)continue;
cout << i << ":" << ans[i] << endl;
}
return 0;
}
思路:先判断是否为全部是数字,之后将之从字符串转换为数字之后判断是否为【1,1000】的范围.
#include<iostream>
#define _CRT_SECURE_NO_WARNINGS 1
#include<string.h>
#include<set>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int gcd(int x, int y)
{
if (x < 0)x *= (-1);
if (y < 0)y *= (-1);
int tmp;
if (x < y)
{
tmp = x; x = y; y = tmp;
}
while (y > 0)
{
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main()
{
char a[1005], b[1005];
int a1 = -1, b1 = -1;
char c;
int pan = 2;
while ((c = getchar()) != '\n')
{
if (c == ' ' && pan == 2)
{
a[++a1] = '\0';
pan -= 1;
continue;
}
if (pan == 2)a[++a1] = c;
else b[++b1] = c;
}
b[++b1] = '\0';
int la = strlen(a), lb = strlen(b);
bool zqa = 1, zqb = 1;
for (int i = 0; i < la; i++)
{
if (a[i] < '0' || a[i]>'9')
{
zqa = 0;
break;
}
}
for (int i = 0; i < lb; i++)
{
if (b[i] < '0' || b[i]>'9')
{
zqb = 0;
break;
}
}
int mul = 1;
bool pana = 1, panb = 1;
unsigned long long numa1 = 0, numb2 = 0;
for (int i = la - 1; i >= 0; i--)
{
numa1 += (a[i] - '0') * mul;
mul *= 10;
if (numa1 > 1000)
{
pana = 0;
break;
}
}
if (numa1 == 0)pana = 0;
mul = 1;
for (int i = lb - 1; i >= 0; i--)
{
numb2 += (b[i] - '0') * mul;
mul *= 10;
if (numb2 > 1000)
{
panb = 0;
break;
}
}
if (numb2 == 0)panb = 0;
if (pana == 0||zqa==0)
{
cout << '?';
}
else cout << numa1;
cout << " + ";
if (panb == 0||zqb==0)
{
cout << '?';
}
else cout << numb2;
cout << " = ";
if (pana == 0 || panb == 0)
{
cout << '?';
}
else cout << numa1 + numb2;
/*
int ans[10001] = { 0 }, yu = 0;
int cura = la - 1, curb = lb - 1;
int i;
for (i = 10000; cura >= 0 || curb >= 0; i--, curb--, cura--)
{
if (cura >= 0 && curb >= 0)
{
ans[i] += (a[cura] - '0') + (b[curb] - '0');
yu = ans[i] / 10;
ans[i - 1] += yu;
ans[i] %= 10;
}
else if (cura >= 0 && curb < 0)
{
ans[i] += (a[cura] - '0');
yu = ans[i] / 10;
ans[i - 1] += yu;
ans[i] %= 10;
}
else if (cura < 0 && curb >= 0)
{
ans[i] += (b[curb] - '0');
yu = ans[i] / 10;
ans[i - 1] += yu;
ans[i] %= 10;
}
}
int p = 0;
for (; ans[p] == 0; p++)
{
}
for (; p < 10001; p++)
{
cout << ans[p];
}
*/
return 0;
}
思路:首先需要判断最多可以完整打出几层的沙漏,同时计算出多余的符号数目,之后根据得出的沙漏层数打印即可。
#include<iostream>
#define _CRT_SECURE_NO_WARNINGS 1
#include<string.h>
#include<set>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int gcd(int x, int y)
{
if (x < 0)x *= (-1);
if (y < 0)y *= (-1);
int tmp;
if (x < y)
{
tmp = x; x = y; y = tmp;
}
while (y > 0)
{
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main()
{
int n;
int sum = 0;
cin >> n;
char a;
cin >> a;
n += 1;
int p;
for (p = 1; sum <= n; p +=1)
{
sum += 2 * (2*p-1);
if (sum > n)
{
p -= 1;
sum -= 2 * (2*p-1);
break;
}
}
sum = p * p*2;
for (int o = p; o > 0; o--)
{
for (int i = 0; i < (2 * p)-1+o-p; i++)
{
if (i < p - o)cout << " ";
else cout << a;
}
cout << endl;
}
for (int o = 2; o <= p; o++)
{
for (int i = 0; i < 2 * p-1+o-p; i++)
{
if (i < p - o)cout << " ";
else cout << a;
}
cout << endl;
}
cout << n - sum;
return 0;
}
关键在于去重,用数组记录曾经释放过技能的行和列即可。
#include<iostream>
#define _CRT_SECURE_NO_WARNINGS 1
#include<string.h>
#include<set>
#include<set>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
int gcd(int x, int y)
{
if (x < 0)x *= (-1);
if (y < 0)y *= (-1);
int tmp;
if (x < y)
{
tmp = x; x = y; y = tmp;
}
while (y > 0)
{
tmp = x % y;
x = y;
y = tmp;
}
return x;
}
int main()
{
int n, m, q;
cin >> n >> m >> q;
int d, num;
int h[100005] = { 0 }, l[100005] = { 0 };
for (int i = 0; i < q; i++)
{
cin >> d >> num;
if (d == 0)
{
if (h[num] == 0)
{
n--;
h[num] = 1;
}
}
else if (d == 1)
{
if (l[num] == 0)
{
m--;
}
}
}
cout << n*m;
return 0;
}
思路:朋友的判断需要用并查集,敌人的判断只需要用set装pair即可,判断方便。
#include <iostream>
using namespace std;
int pref[1005], preo[105][105] = { 0 };
int find(int i)
{
while (pref[i] != i)
{
i = pref[i];
}
return i;
}
int main()
{
int n, m, k;
cin >> n >> m >> k;
for (int i = 0; i <= n; i++)
{
pref[i] = i;
}
int x, y, r;
for (int i = 0; i < m; i++)
{
cin >> x >> y >> r;
if (r == (-1))
{
preo[x][y] = 1;
preo[y][x] = 1;
}
if (r == 1)
{
if (find(x) != x)
{
pref[find(y)] = find(x);
}
else
{
pref[x] = find(y);
}
}
}
for (int i = 0; i < k; i++)
{
cin >> x >> y;
if (preo[x][y] == 1 && find(x) != find(y))
{
cout << "No way\n";
continue;
}
else if (preo[x][y] == 1 && find(x) == find(y))
{
cout << "OK but...\n";
continue;
}
else if (find(x) == find(y))
{
cout << "No problem\n";
continue;
}
else cout << "OK\n";
}
return 0;
}
思路:用set装pair,first为分数,second为名称的string串。并且记录每个分值的人数。如果名人堂中同一分数有多人的话,因为按字典序升序排得,所以需要往前遍历知道找到第一个同分的位置然后输出至同分的最后一个位置,满足字典序升序。
#include <iostream>
#include<string>
#include<utility>
#include<set>
using namespace std;
int n, g, k;
set<pair<int, string>>s;
int main()
{
pair<int, string>p;
int b[101] = { 0 };
long long price = 0;
cin >> n >> g >> k;
for (int i = 0; i < n; i++)
{
cin >> p.second>> p.first;
b[p.first]++;
if (p.first >= g)price += 50;
else if (p.first >= 60)price += 20;
s.insert(p);
}
cout << price << endl;
auto it = s.end();
it--;
int cur=1,pres=0,cnt=1;
for (; cnt <= k || it->first == pres;it--)
{
if (pres != it->first)
{
cur = cnt;
}
if (b[it->first] > 1)
{
auto tmp = it;
for (int q = 1; q < b[it->first]; q++)
{
tmp--;
}
int biao = tmp->first;
for (; tmp->first == biao; tmp++)
{
cout << cur << " " << tmp->second << " " << tmp->first << endl;
cnt++;
}
for (int q = 1; q < b[it->first]; q++)
{
it--;
}
continue;
}
cout << cur << " "<<it->second<<" "<<it->first<<endl;
pres = it->first;
if (it == s.begin())
{
break;
}
cnt++;
}
return 0;
}
queue,stack的模拟,需要甄别出每种容器的类型。
#include <iostream>
#include<string>
#include<utility>
#include<set>
#include<stack>
#include<queue>
using namespace std;
int n, m, smax;
int main()
{
cin >> n >> m >> smax;
stack<char> s[105];
stack<char>bas;
string str[105];
queue<char> ans;
char tmpi, tmpo;
for (int i = 1; i <= n; i++)
{
cin >> str[i];
}
for (int i = 1; i <= n; i++)
{
for (int o = m-1; o >=0; o--)
{
s[i].push(str[i][o]);
}
}
int opr;
cin >> opr;
while (opr != -1)
{
if (opr == 0)
{
if (!bas.empty())
{
tmpo = bas.top();
bas.pop();
ans.push(tmpo);
}
}
else
{
if (!s[opr].empty())
{
tmpi = s[opr].top();
s[opr].pop();
if (bas.size() < smax)
{
bas.push(tmpi);
}
else
{
tmpo = bas.top();
bas.pop();
bas.push(tmpi);
ans.push(tmpo);
}
}
}
cin >> opr;
}
while (!ans.empty())
{
cout << ans.front();
ans.pop();
}
return 0;
}
#include <cstdio>
#include <set>
#include <queue>
#include <algorithm>
using namespace std;
struct node
{
int f, m, sex;
};
node v[100010];
int level[100010];
bool exist[100010];
int main()
{
int n, m, id, father, mother, a, b;
scanf("%d", &n);
char c;
for (int i = 0; i < n; i++)
{
scanf("%d %c %d %d", &id, &c, &father, &mother);
v[id].f = father, v[id].m = mother;
if (c == 'M') v[id].sex = 0;
else v[id].sex = 1;
exist[id] = true;
v[father].sex = 0;
v[mother].sex = 1;
}
scanf("%d", &m);
for (int i = 0; i < m; i++)
{
fill(level, level + 100010, 0);
scanf("%d%d", &a, &b);
if (v[a].sex == v[b].sex)
{
printf("Never Mind\n");
continue;
}
queue<int> q;
q.push(a);
q.push(b);
level[a] = 1;
level[b] = 1;
set<int> s;
int flag = 0;
while (!q.empty())
{
int top = q.front();
q.pop();
int size = s.size();
s.insert(top);
if (size == s.size())
{
printf("No\n");
flag = 1;
break;
}
if (exist[top] == false)
{
continue;
}
if (level[top] <= 4)
{
int fa = v[top].f;
int mo = v[top].m;
if (fa != -1)
{
q.push(fa);
level[fa] = level[top] + 1;
}
if (mo != -1)
{
q.push(mo);
level[mo] = level[top] + 1;
}
}
}
if (flag == 0)
{
printf("Yes\n");
}
}
return 0;
}