祝各位通关考AK奥利给

注意事项:

1.多组数据

2.行末有无空格

3.初始化

网址:Welcome To ZJUT Online Judge

目录

网址:Welcome To ZJUT Online Judge

1335: C++通关考模拟题--"I love C++"

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 4970  Solved: 2329
[Submit][Status][Web Board]

description

打印"I love C++"(包括引号)

input

output

"I love C++"

Sample Input

Sample Output

"I love C++"

参考代码:

#include<iostream>
using namespace std;
int main()
{cout<<"\"I love C++\"";
} 

problem 1337

1337: C++通关考模拟题--欢迎新同学

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3312  Solved: 2446
[Submit][Status][Web Board]

description

新学期即将来临,学校决定挂一条横幅来欢迎新同学,横幅内容为:“Welcome to ZJUT!”

这么简单的任务相

信你能做到吧。

input

output

Welcome to ZJUT!

Sample Input

Sample Input

Welcome to ZJUT!

参考代码:

#include <iostream>
using namespace std;
int main()
{cout << "Welcome to ZJUT!";
}

problem 1341

1341: C++通关考模拟题--解密

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 8474  Solved: 2060
[Submit][Status][Web Board]

description

A国和B国正在发生大战,B国为了获得胜利,派使者送密报给C国求助。天助A国,现在A国抓住了这个
使者并且获得了密报。但是当A国看到这段密码是全都傻了眼,他们看到的就是乱七八糟的数字。就在
大家乱成一团的时候,一个聪明的大臣看了半天之后发现只需要把每五个数字加起来,结果对26取模,
然后用0 对应a,1对应b...以此类推即

input

多组输入,每组第一行输入n,接下来n行,每行5个数字,每个数字之间用空格分隔。

output

输出最终的明文,每行一个小写字母

Sample Input

3
1 2 3 4 5
3 2 5 8 4
6 9 8 5 4

Sample Output

p
w
g

参考代码:

#include <iostream>
using namespace std;
int main()
{int n;while (cin >> n){while (n--){int t;int sum = 0;for (int i = 1; i <= 5; i++)cin >> t, sum += t;sum %= 26;cout << char('a' + sum) << endl;}}
}

problem 1347

1347: C++通关考模拟题--最大公约数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 6145  Solved: 2230
[Submit][Status][Web Board]

description

根据读入的两个正整数,计算他们的最大公约数,数据有多组。

input

第一行是一个正整数n(1<=n<=50),接下来n行每行包括两个正整数a和b(1<=a,b<=10000);

output

每行输出形式为Case t: x,其中t从1到n,x为运算答案,共n行。

Sample Input

5
20 494
2172 5298
3789 54
3065 7899
3294 5967
Sample OutputCase 1: 2
Case 2: 6
Case 3: 9
Case 4: 1
Case 5: 27

参考代码:

#include <iostream>
using namespace std;
int gcd(int a, int b)
{int c;while (a % b != 0){c = a % b;a = b;b = c;}return b;
}
int main()
{int n;while (cin >> n){int i = 1;while (i <= n){int a, b;cin >> a >> b;cout << "Case " << i << ": " << gcd(a, b) << endl;i++;}}
}

problem 1356

1356: C++通关考模拟题--懒洋洋小明

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3732  Solved: 1790
[Submit][Status][Web Board]

description

小明是一个很懒的人,比如说,计算1234+69,他只会计算4+9,对于答案也只记录3,简单的说,就是只对个位数进行计算。那么对于一下数据,请输出小明式答案。

input

有多组数据,每组数据包括a,b(a,b<=10000);

output

对每组数据输出小明式答案。

Sample Input

29 3690
1972 5892
8814 352

Sample Output

9
4
6

参考代码:

#include <iostream>
using namespace std;
int gcd(int a, int b)
{int c;while (a % b != 0){c = a % b;a = b;b = c;}return b;
}
int main()
{int a, b;while (cin >> a >> b){cout << (a % 10 + b % 10) % 10 << endl;}
}

problem 1358

1358: C++通关考模拟题--奇偶数分离

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 4135  Solved: 1668
[Submit][Status][Web Board]

description

有一个整型偶数n(2<=n<=1000),你要做的是:先把1到n中的所有偶数从小到大输出,再把所有的偶数从小到大输出。

input

第一行有一个整数i(2<=i<30),表示有i组测试数据,
每组的输入是一个整型偶数n。

Output

第一行输出所有的奇数,第二行输出所有的偶数,
每两个数中间有一个空格,最后一个数的末尾没有空格

Sample Input

2
10
14

Sample Output

1 3 5 7 9
2 4 6 8 10
1 3 5 7 9 11 13
2 4 6 8 10 12 14

参考代码

#include <iostream>
using namespace std;
int gcd(int a, int b)
{int c;while (a % b != 0){c = a % b;a = b;b = c;}return b;
}
int main()
{int n;cin >> n;while (n--){int m;cin >> m;int i = 3;cout << 1;while (i <= m)cout << ' ' << i, i += 2;cout << endl<< 2;i = 4;while (i <= m)cout << ' ' << i, i += 2;cout << endl;}
}

problem 1361

1361: C++通关考模拟题--计算两点间的距离

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 4977  Solved: 1625
[Submit][Status][Web Board]

description

输入两点坐标(X1,Y1),(X2,Y2),计算并输出两点间的距离。

input

输入数据有多组,每组占一行,由4个实数组成,分别表示x1,y1,x2,y2,数据之间用空格隔开

output

对于每组输入数据,输出一行,结果保留两位小数。

Sample Input

0 0 0 1
0 1 1 0

Sample Output

1.00
1.41

参考代码 :

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int gcd(int a, int b)
{int c;while (a % b != 0){c = a % b;a = b;b = c;}return b;
}
int main()
{double x1, x2, y1, y2;while (cin >> x1 >> y1 >> x2 >> y2)cout << fixed << setprecision(2) << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;
}

problem 1367

1367: C++通关考模拟题--Palindrome

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2561  Solved: 970
[Submit][Status][Web Board]

Description

There are many character strings.You should judge which one is the palindrome .

input

There are including several test cases.Every case occupies one line.Every line has one character string .the end line is 0,and this line needn’t to be processed.

output

If the Character string is palindrome output “Yes”,else “No”.

Sample Input

12321
abbab
0

Sample Output

Yes
No

参考代码:

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;
int gcd(int a, int b)
{int c;while (a % b != 0){c = a % b;a = b;b = c;}return b;
}
int main()
{string x;while (cin >> x){if (x == "0")break;bool flag = 1;for (int i = 0; i < x.length() / 2; i++)if (x[i] != x[x.length() - 1 - i])flag = 0;if (flag)cout << "Yes\n";elsecout << "No\n";}
}

problem 1368

1368: C++通关考模拟题--合并列表

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 7889  Solved: 1420
[Submit][Status][Web Board]

description

小明从老师那里拿到了两组数据(int就可以),但是呢,都是乱码的,现在要把这两组数据合并成一组有序的数据归还给老师。但是他不会做。希望你能帮助他。
现在就看你的啦。

input

有好几组测试数据。每一组数据包括两行。
第一行的第一个数表示第一组数据的个数N(0<=N<=1000)。后面N个数表示第一组数据。
第二行第一个数表示第二组数据的个数M(0<=M<=1000)。后面M个数表示第二组数据。

output

对于每一个测试样例。输出合并后的数据。
两个不同的数据之间用空格隔开。
每两个不同的测试样例之间用空行表示

Sample Input

2 1 3
4 6 7 3 4

Sample Output

1 3 3 4 6 7

参考代码:

#include<iostream>
#include<algorithm>
using namespace std;
int main()
{int n,m,a[20001];int ans=0;while(cin>>n){ans++  ;for(int i=1;i<=n;i++) cin>>a[i];cin>>m;for(int i=n+1;i<=n+m;i++) cin>>a[i];sort(a+1,a+1+n+m);for(int i=1;i<=n+m-1;i++) cout<<a[i]<<" ";cout<<a[n+m]<<endl<<endl;}}

problem 1373

1373: C++通关考模拟题--Light bubble

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3027  Solved: 619
[Submit][Status][Web Board]

description

There are N lights in a empty room,numbering from 1 to N.The first person should turn all the lights on,and the second one should press those switches whose number is the multiple of 2 (those light will be turned off).And the third person should press those switches whose number is the multiple of 3 (the light on will be turned off,and the light off will be turned on).and so on.there K persons.
As a result ,which light will be on finally?

input

There several test cases.
Every case includes N and K.(K<=N<=1000)

output

Output all the numbers when the light is on.
There is a space between two different numbers.And there is a blank line between two different case.

Sample Input

4 2
6 2

Sample Output

1 31 3 5

参考代码:

#include <iostream>
#include <cstring>
using namespace std;
int main()
{int n, k;bool flag[1001];while (cin >> n >> k){memset(flag, 1, sizeof(flag));for (int i = 2; i <= k; i++){int k = i;while (k <= n){flag[k] = !flag[k];k += i;}}cout << 1;for (int i = 2; i <= n; i++)if (flag[i])cout << ' ' << i;cout << endl;cout << endl;}
}

problem 1374

1374: C++通关考模拟题--温度换算

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1969  Solved: 1328
[Submit][Status][Web Board]

description

华氏温度和摄氏温度是目前比较常用的温度表示单位,如英国、美国、加拿大、澳大利亚和印度等国多用华氏温度;而世界科技界和工农业生产中,以及我国、法国等国家则多用摄氏温度。
我们知道,水的冰点是0°C或32°F,沸点是100°C或212°F。设计一个程序,将摄氏温度换算为华氏温度。

input

输入含有一些整数n(-100≤n≤500),表示摄氏温度,若n为999表示处理结束。

output

分别计算摄氏温度n所对应的华氏温度值(保留一位小数),每个输出占一行。

Sample Input

150
-23
3
0
999

Sample Output

302.0
-9.4
37.4
32.0

参考代码

#include <bits/stdc++.h>
using namespace std;
int main()
{double n;while (cin >> n){if (n == 999)break;cout << fixed << setprecision(1) << 32 + 1.8 * n << endl;}
}

problem 1337

1377: C++通关考模拟题--全排列

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1649  Solved: 580
[Submit][Status][Web Board]

description

全排列想必大家都知道吧。例如1~3
的全排列是1 2 3; 1 3 2; 2 1 3; 2 3 1; 3 1 2; 3 2 1。

input

输入数据有多组,每行输入一个整数n(1<=n<=7)

output

按顺序输出1~n的全排列。每个全排列之间的数用空格隔开。

Sample Input

3
2

Sample Output

1 2 3
1 3 2
2 1 3
2 3 1
3 1 2
3 2 1
1 2
2 1

参考代码:

#include <bits/stdc++.h>
using namespace std;
int n;
int a[9];
void dfs(int k)
{if (k == n){cout << a[0];for (int i = 1; i < n; i++)cout << ' ' << a[i];cout << endl;return;}for (int i = 1; i <= n; i++){bool flag = 1;for (int j = 0; j < k; j++)if (a[j] == i){flag = 0;break;}if (flag){a[k] = i;dfs(k + 1);}}
}
int main()
{while (cin >> n)dfs(0);
}

problem 1384

1384: C++通关考模拟题--2^k?

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3658  Solved: 1129
[Submit][Status][Web Board]

description

判断一个正整数能不能写成2的k次,k是整数

input

第一行输入一个整数N,表示测试数据的组数(1<N=<20)
每组数据只有一个数M(1<=M<=1000)

output

每组输出一行,如果M可以写成2的k次就输出Yes,否则输出No

Sample Input

3
2
5
16

Sample Output

Yes
No
Yes

参考代码:

#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{cin >> n;while (cin >> n){if (int(log2(n)) - log2(n) == 0)cout << "Yes";elsecout << "No";cout << endl;}
}

problem 1386

1386: C++通关考模拟题--连接字符串

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2830  Solved: 1353
[Submit][Status][Web Board]

description

给你两个字符串,主要把这两个字符串前后连接好输出就可以了

input

第一行输入一个整数N,表示测试数据的组数(1<N=<20)
每组数据只有一行,是两个字符串,中间有空格隔开,每个字符串都是小写字母组成的,每个字符串长度不超过100

output

输出一行表示连接后的字符串

Sample Input

1
acm zjut

Sample Output

acmzjut

参考代码:

#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{int t;cin >> t;while (t--){string a, b;cin >> a >> b;cout << a << b << endl;}
}

problem 1387

1387: C++通关考模拟题--加减乘数取余

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1766  Solved: 895
[Submit][Status][Web Board]

description

给你一个数,根据输入对这个数进行加减乘除或是取余操作,其中除操作是结果都为整数的除操作,操作后的结果将替换该数

input

第一行输入一个整数N,表示测试数据的组数(1<N=<10)
第二行有两个正整数m,p,分别表示初始数值和操作次数,接下来的p行,每行两个正整数t,k,分别表示操作类型和操作数,t=1表示加
操作,t=2表示减操作,t=3表示乘操作,t=4表示除操作,t=5表示取余操作,对每种操作对象都是m和k,格式是m+k,m-k,m*k,m/k,m%k,
1<=t<=5,1<=m,p,k<=100,

output

每组测试数据只输出一行,即完成所有操作后该数的值,保证该值在int范围内

Sample Input

1
5 5
1 2
2 3
3 4
4 5
5 6

Sample Output

3

参考代码:

#include<bits/stdc++.h>
using namespace std;
int n;
int main()
{int n;cin>>n;while(n--){int m,p;cin>>m>>p;while(p--){int t,k;cin>>t>>k;if(t==1) m+=k;if(t==2) m-=k;if(t==3) m*=k;if(t==4) m/=k;if(t==5) m%=k;}cout<<m<<endl;}
}

problem 1389

1389: C++通关考模拟题--oh my God!(二)

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2643  Solved: 1073
[Submit][Status][Web Board]

description

输入一个数字n, 输出n个”oh my God”(不包括引号),每句后面有个逗号,最后一句是句号

input

输入多组数据,每组数据占一行,有一个整型数据n < 100

output

按题目描述输出

Sample Input

3

Sample Output

oh my God,
oh my God,
oh my God.

参考代码:

​
#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{int n;while (cin >> n){n--;while (n--)cout << "oh my God,\n";cout << "oh my God.\n";}
}​

problem 1392

1392: C++通关考模拟题--字符三角形

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2552  Solved: 1427
[Submit][Status][Web Board]

description

输入一个数字n, 输出’*’字符的直角三角形

input

输入多组数据,每组数据占一行,为一个整型数字n <30

output

输出’*’字符的直角三角形,具体看Sample

Sample Input

3

Sample Output

***
**
*

参考代码:

#include <bits/stdc++.h>
using namespace std;
int n;
int main()
{int n;while (cin >> n){for (int i = 1; i <= n; i++){for (int j = 1; j <= n + 1 - i; j++)cout << "*";cout << endl;}}
}

problem 1396

1396: C++通关考模拟题--欧拉回路

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 504  Solved: 250
[Submit][Status][Web Board]

description

给你一堆点,点与点之间有无向边,问是否存在欧拉回路,假设所有点都在一个连通块

input

有多组案例,每组第一行有两个数n,m,n <= 15表示点数,m <= n*(n-1)/2表示边数
接下来有m行,每行有两个数字 1 <= a,b <= n (a != b)

output

若存在欧拉回路,输出”Yes”
否则输出”No”

Sample Input

3 3
1 2
2 3
3 1
4 4
1 2
2 3
1 3
1 4

Sample Output

Yes
No

参考代码:

#include <iostream>
#include <vector>
using namespace std;
int n;
vector<int> a[16];
int main()
{int m;while (cin >> n >> m){for (int i = 1; i <= 15; i++)a[i].clear();int x, y;while (m--){cin >> x >> y;a[x].push_back(y);a[y].push_back(x);}bool flag = 1;for (int i = 1; i <= 15; i++)if (a[i].size() & 1){flag = 0;}if (flag)cout << "Yes\n";elsecout << "No\n";}
}

problem 1398

1398: C++通关考模拟题--长方形

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 4223  Solved: 1231
[Submit][Status][Web Board]

description

给定长和宽,请输出一个长方形,并a-z按顺序填充。

input

多组数据,读到文件末
每组数据输入a,b代表宽和高,0<a,b<=20

output

请输出以字符为填充的长方形,每个图案之间空一行。

Sample Input

2 3
4 2

Sample Output

ab
cd
efabcd
efgh

参考代码:

#include <iostream>
using namespace std;
int main()
{int a, b;while (cin >> a >> b){for (int i = 1; i <= b; i++){for (int j = 1; j <= a; j++)cout << char('a' + ((i - 1) * a + j - 1) % 26);cout << endl;}cout << endl;}
}

problem 1412

1412: C++通关考模拟题--画口

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3183  Solved: 1270
[Submit][Status][Web Board]

description

根据读入的矩阵的长和宽,输出笔画粗细为1的“口”字。

input

输入不超过10组样例,每组数据包括两个整数n(3≤n≤30),m(3≤n≤30),分别代表长和宽。

output

输出填充字符为‘#’,长为n,宽为m的“口”字,两组样例之间空一行。

Sample Input

4 4
5 6

Sample Output

####
#  #
#  #
##########
#    #
#    #
#    #
######

参考代码:

#include <iostream>
using namespace std;
int main()
{int a, b;while (cin >> a >> b){for (int i = 1; i <= a; i++){if (i == 1 || i == a){for (int j = 1; j <= b; j++)cout << "#";}else{for (int j = 1; j <= b; j++)if (j == 1 || j == b)cout << "#";elsecout << ' ';}cout << endl;}cout << endl;}
}

problem 1414

1414: C++通关考模拟题--排序

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3021  Solved: 1537
[Submit][Status][Web Board]

description

输入一个乱序的数组,输出其升序排序后的结果

input

多组样例,
每组样例首先是一个N(1<=n<=20),表示有N个数,之后是N个数,表示给定的乱序的数组。

output

输出排序后的数组,两个数字之间用一个空格隔开,最后一个数后面不能有空格。

Sample Input

3 3 2 1
5 1 5 3 2 7

Sample Output

1 2 3
1 2 3 5 7

参考代码:

#include <iostream>
#include <algorithm>
using namespace std;
int main()
{int n;while (cin >> n){int a[21];for (int i = 1; i <= n; i++)cin >> a[i];sort(a + 1, a + 1 + n);cout << a[1];for (int i = 2; i <= n; i++)cout << " " << a[i];cout << endl;}
}

problem 1415

1415: C++通关考模拟题--数字查找

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3157  Solved: 1461
[Submit][Status][Web Board]

description

对于给定的一组数字,查找某一个数字是否在其中。

input

多组样例。
每组样例首先是一个N(1<=N<=100),表示接下来有N个数字。
接下来一行是N个数,表示给定的数组。
最后是一个M,表示要查询的数。

output

若要查询的数字在数组中,则输出YES,否则输出NO

Sample Input

3
1 2 3
2
4
1 3 5 7
6

Sample Output

YES
NO

problem 1415

1415: C++通关考模拟题--数字查找

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3157  Solved: 1461
[Submit][Status][Web Board]

description

对于给定的一组数字,查找某一个数字是否在其中。

input

多组样例。
每组样例首先是一个N(1<=N<=100),表示接下来有N个数字。
接下来一行是N个数,表示给定的数组。
最后是一个M,表示要查询的数。

output

若要查询的数字在数组中,则输出YES,否则输出NO

Sample Input

3
1 2 3
2
4
1 3 5 7
6

Sample Output

YES
NO

参考代码:

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main()
{int n;while (cin >> n){set<int> m;int t;for (int i = 1; i <= n; i++){cin >> t;m.insert(t);}cin >> t;if (m.find(t) != m.end())cout << "YES\n";elsecout << "NO\n";}
}

problem 1412

1422: C++通关考模拟题--求平均数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 4801  Solved: 1027
[Submit][Status][Web Board]

description

有n个数a1-an,求出他们的平均数(四舍五入取整)

input

整数0<n<100,0<an<1000

output

输出平均数

Sample Input

5
1 2 3 4 5

Sample Output

3

参考代码:

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
int main()
{int n;while (cin >> n){double sum = 0;int k = n;double t;while (k--)cin >> t, sum += t;if (-int(sum / n) + sum / n >= 0.5)cout << int(sum / n) + 1;elsecout << int(sum / n);cout << endl;}
}

problem 1423

1423: C++通关考模拟题--2进制

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 4018  Solved: 1236
[Submit][Status][Web Board]

description

输入一个正整数n输出n的2进制

input

整数0<n<10^9

output

输出n的二进制

Sample Input

16

Sample Output

10000

参考代码:

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;
void f(int n)
{if (n == 0)return;f(n / 2);cout << n % 2;
}
int main()
{int n;while (cin >> n){if (n == 0)cout << 0;elsef(n);cout << endl;}
}

problem 1427

1427: C++通关考模拟题--本金利息

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2075  Solved: 801
[Submit][Status][Web Board]

description

在银行中存了n元,年利率为a%,计算m年后本金加利息有多少。(结果保留整数)

input

0<10000, 0<a<10, 整数0<m<50

output

如题

Sample Input

1500 5 40

Sample Output

10560

参考代码:

#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int main()
{double n, a, m;while (cin >> n >> a >> m){while (m--)n *= (1 + a / 100);cout << fixed << setprecision(0) << n << endl;}
}

problem 1458

1458: C++通关考模拟题--Take the XXX

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2150  Solved: 1446
[Submit][Status][Web Board]

description

Take the XXX是英语语法中常用的一个词组,本题的要求为对于给定的多个单词,给出它的这种词组形式(保证单词有这种词组形式,单词长度<=20)

input

输入数据为多个单词,每行表示一个单词。

output

对于每行给定的单词,输出一行“Take the XXX”形式的词组。

Sample Input

bed
lead

Sample Output

Take the bed
Take the lead

参考代码:

#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int main()
{string a;while (cin >> a){cout << "Take the " << a << endl;}
}

problem 1459

1459: C++通关考模拟题--正负判断

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1325  Solved: 925
[Submit][Status][Web Board]

description

任何数字都有正负之分,假设我们定义0也为正数,对于给定的数字x(-100000<=x<=100000),若它为正数,就输出“positive”,若为负数,输出“negative”。

input

输入数据为多个数字,每行表示一个数字。

output

对于每行给定的数字,根据题目要求输出“positive”或“negative”

Sample Input

5
-5

Sample Output

positive
negative

参考代码:

#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int main()
{int a;while (cin >> a){if (a < 0)cout << "negative\n";elsecout << "positive\n";}
}

problem 1460

1460: C++通关考模拟题--大小数计数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2375  Solved: 1075
[Submit][Status][Web Board]

description

给n个数字,然后给个数字x,输出这n个数字中大于x的数量和小于x的数量,等于x的忽略。

input

输入数据为多组数据。第一行输入n和x,第二行输入n个数字(n<=1000,所有数字<=100000,且为正整数).

output

第一行输出大于x的数量,第二行输出小于x的数量。每组输出后都要额外输出一个空行。

Sample Input

3 2
1 2 3
4 3
5 5 5 5

Sample Output

1
14
0

参考代码:

#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
using namespace std;
int main()
{int n, x;while (cin >> n >> x){int t, s1 = 0, s2 = 0;while (n--){cin >> t;if (t > x)s1++;else if (t < x)s2++;}cout << s1 << endl<< s2 << endl<< endl;}
}

problem 1461

1461: C++通关考模拟题--4的个数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1670  Solved: 1171
[Submit][Status][Web Board]

description

给定一个正整数(<=100000),求该数数位上4的数量。

input

输入数据为数字,每行一个数字。

output

对于每行给定的数字,输出一行该数字数位上4的数量。

Sample Input

14
44

Sample Output

1
2

参考代码:

#include<iostream>
#include<algorithm>
#include<set>
#include<iomanip>
using namespace std;
int main()
{int n;while(cin>>n){int s=0;while(n) {if(n%10==4) s++;n/=10;}cout<<s<<endl;}
}

problem 1462

1462: C++通关考模拟题--矩形嵌套输出

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 3411  Solved: 708
[Submit][Status][Web Board]

description

输入n,m,其中m<n(n,m<=40),,并且n和m保证为2的倍数。输出如下的图案。

input

输入数据为多组数据,每行一个n和一个m。

output

每组数据输出指定图案。详细请看样例。

Sample Input

4 2
6 4

Sample Output

****
*  *
*  *
****
******
*    *
*    *
*    *
*    *
******

参考代码:

#include <iostream>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cstring>
using namespace std;
int main()
{int n, m;while (cin >> n >> m){char a[50][50];memset(a, '*', sizeof(a));for (int i = 1 + (n - m) / 2; i <= (n - m) / 2 + m; i++)for (int j = 1 + (n - m) / 2; j <= (n - m) / 2 + m; j++)a[i][j] = ' ';for (int i = 1; i <= n; i++){for (int j = 1; j <= n; j++)cout << a[i][j];cout << endl;}}
}

problem 1463

1463: C++通关考模拟题--最大公约数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1810  Solved: 1172
[Submit][Status][Web Board]

description

题目很简单,就是求三个正整数的最大公约数。

input

输入数据为多组数据,每行3个数字(<=1000)。

output

对于每行给定三个数字,输出一行为三个数字的最大公约数。

Sample Input

1 2 3
2 4 6

Sample Output

1
2

参考代码:

#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b)
{int c;while (a % b != 0){c = a % b;a = b;b = c;}return b;
}
int main()
{int a, b, c;while (cin >> a >> b >> c){cout << gcd(gcd(a, b), c) << endl;}
}

problem 1464

1464: C++通关考模拟题--三个水杯

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2636  Solved: 869
[Submit][Status][Web Board]

description

桌上有三个水杯,已知三个水杯容量固定为20,我们规定A水杯向B水杯倒水,指的是倒至不能再倒为止,即要么A水杯水空了,或B水杯倒满了,才算这次倒水结束。现给出三个水杯初始时的水量,和n个倒水方向(1 2表示1水杯向2水杯倒水)。求最终三个水杯的水量情况。

input

输入数据为多组数据,每组数据初始为三个数字(<=20),表示三个水杯的初始水量。然后一个n(<=100),紧接着n行,每行两个数字,表示某水杯倒向另一个水杯。

output

对于每组数据,输出三个数字,表示1-3水杯的最终水量。

Sample Input

5 5 5
2
1 2
3 2

Sample Output

0 15 0

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{int a[4];while (cin >> a[1] >> a[2] >> a[3]){int n;cin >> n;while (n--){int x, y;cin >> x >> y;if (a[x] + a[y] >= 20){int s = a[x] + a[y];a[x] = s - 20;a[y] = 20;}else{a[y] += a[x];a[x] = 0;}}cout << a[1] << ' ' << a[2] << ' ' << a[3] << endl;}
}

problem 1466

1466: C++通关考模拟题--绝对值数列

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2070  Solved: 879
[Submit][Status][Web Board]

description

已知某数列,a[i]=|a[i-1]-a[i-2]|(i>2),给出指定的a1和a2,求an。

input

输入数据为多组数据,为一行三个数字a1,a2,n(a1,a2<=1000,n<=1000).

output

对于每组数据,输出一行1个整数为an.

Sample Input

2 3 5
1 1 6

Sample Output

1
0

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{int a[1010], n;while (cin >> a[1] >> a[2] >> n){for (int i = 3; i <= n; i++)a[i] = abs(a[i - 1] - a[i - 2]);cout << a[n] << endl;}
}

problem 1467

1467: C++通关考模拟题--考试安排

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 2025  Solved: 344
[Submit][Status][Web Board]

description

小明本学期有四门考试要考,每门考试考一天,哪天考什么由他自己决定,小明列了个自己在第几天考第几门的发挥程度矩阵(4*4),然后问题就来了,小明该如何安排考试,使自己考试发挥最佳。

input

输入数据为多组数据,每组数据有四行,每行四个数字,表示自己在第几天(行)考第几门(列)的发挥程度(<=1000的正整数)。

output

对于每组数据,输出最高的总发挥程度。

Sample Input

1 1 1 3
1 1 3 1
1 3 1 1
3 1 1 1

Sample Output

12

参考代码:

​
#include <bits/stdc++.h>
using namespace std;
int ma = 0;
int a[5][5], b[5];
void f(int k)
{if (k == 4){int s = 0;for (int i = 0; i < 4; i++)s += a[i + 1][b[i]];if (s > ma)ma = s;return;}for (int i = 1; i <= 4; i++){bool flag = 1;for (int j = 0; j < k; j++)if (b[j] == i){flag = 0;break;}if (flag){b[k] = i;f(k + 1);}}
}
int main()
{while (~scanf("%d%d%d%d", &a[1][1], &a[1][2], &a[1][3], &a[1][4])){ma = 0;for (int i = 2; i <= 4; i++)for (int j = 1; j <= 4; j++)cin >> a[i][j];f(0);cout << ma << endl;}
}​

problem 1469

1469: C++通关考模拟题--计算

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 944  Solved: 786
[Submit][Status][Web Board]

description

计算(a+b)/c的值。(有多组数据,a,b,c均为整数,/为整除)

input

每行包含三个整数,a,b,c.

output

(a+b)/c的值

Sample Input

1 2 3
2 1 3

Sample Output

1
1

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{int a, b, c;while (cin >> a >> b >> c){cout << (a + b) / c << endl;}
}

problem 1497

1497: C++通关考模拟题--盛世繁花

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 986  Solved: 470
[Submit][Status][Web Board]

description

KK很喜欢花朵,所以她在自己的花园里种满了鲜花。但是有些花开得实在是小,KK很难分辨到底有多少鲜花。今天她想知道自己的花园里开了多少花了,于是高度近视的她请你帮她数一数一共有多少花。

input

首先输入一个正整数T(T<=500),代表之后会有几种测试数据。之后会输入一个整数n(n<=500),代表之后会输入几行字符串。‘#’代表叶子,‘*’代表迎春花,‘%’代表梅花,‘:’代表代表变化•••每个字符串内都没有‘ ’。输入的字符串里不包含除上面四个字符以外的字符。

每行输出这种情况下有多少花,不能出现负数

output

Sample Input

2
4
########
********
::::::::
********
1
#

Sample Output

24
0

参考代码 :

#include <bits/stdc++.h>
using namespace std;
int main()
{int t;cin >> t;while (t--){int n;cin >> n;string s;int sum = 0;while (n--){cin >> s;for (int i = 0; i < s.length(); i++)if (s[i] != '#')sum++;}cout << sum << endl;}
}

problem 1498

1498: C++通关考模拟题--满天繁星

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 968  Solved: 584
[Submit][Status][Web Board]

description

KK是个喜欢浪漫的女孩子,这天她在晚上看星星,觉得漫天的繁星真是美丽,恰好她又喜欢画画,所以她便想画出堪比天上星星的星星,不巧她晚上在外面呆久了感冒了,所以这事只能拜托你啦~

input

输入一个整数n(n<=40),代表要画几颗星星,当n=0时结束

output

所有的星星都一样,详见Sample Output。

Sample Input

3
0

Sample Output

           **   **   *       *   **           **   *   ** *     * **           ***   **   *       *   **           **   *   ** *     * **           ***   **   *       *   **           **   *   ** *     * **           *

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{int n;while (cin >> n && n){while (n--){cout << "           *\n";cout << "         *   *\n";cout << "   *   *       *   *\n";cout << "     *           *\n";cout << "       *   *   *\n";cout << "      * *     * *\n";cout << "     *           *\n";}}
}

problem 1499

1499: C++通关考模拟题--KK的代码

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1305  Solved: 726
[Submit][Status][Web Board]

description

KK作为一枚程序媛,自然是要写代码的,她最近试了试hello word,才写了一部分代码,就出去了,于是你要把剩下的代码写好拷贝给她,以作为参考。请输出你的代码吧O(∩_∩)O~。

input

output

输出Sample Output里的所有代码。

Sample Input


Sample Output

cout<<"hello world"<<endl;//输出
return 0;

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{cout << "cout<<\"hello world\"<<endl;//输出\nreturn 0;";
}

problem 1500

1500: C++通关考模拟题--卡特兰数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1418  Solved: 281
[Submit][Status][Web Board]

description

KK最近从一个傻X那里听说了卡特兰数,但是傻X又不告诉她卡特兰数是什么,现在傻×要考KK卡特兰数,你能告诉KK答案吗?

input

输入整数n(n<=33),当n=0时结束。

output

输出n:对应的卡特兰数。

Sample Input

1
5
0

Sample Output

1: 1
5: 42

参考代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{ll a[34] = {0};a[0] = 1;for (int i = 1; i <= 33; i++){for (int j = 0; j < i; j++)a[i] += (a[j] * a[i - 1 - j]);}int n;while (cin >> n && n){cout << n << ": " << a[n] << endl;}
}

problem 1501

1501: C++通关考模拟题--KK的秘密通信

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 448  Solved: 278
[Submit][Status][Web Board]

description

KK最近和饲养员大叔聊得火热,可惜室友们总是要凑上来偷看八卦,所以KK和饲养员大叔约定使用一些手段来加密消息,如a->fasa,aba->gdsabafdf,abcdcba->fdsabcdcball,即在回文字符串的基础上加一些干扰字符串,最长的回文字符串既是真正的消息。你能火眼金睛吗?

input

输入有多行字符串,其中包括字母(字母区分大小写),数字,符号。 不用判断结束 。

output

与输入相对应每一行输出一个整数,代表最长有效密码串的长度。

Sample Input

ABBA
12ABBA
A
ABAKK
51233214
abaaab

Sample Output

4
4
1
3
6
5

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{string temp, x;while (cin >> x){bool flag = 1;for (int i = x.length(); i >= 1 && flag; i--){for (int j = 0; j + i - 1 < x.length() && flag; j++){bool fla = 1;for (int k = j; k <= j + i - 1; k++)if (x[k] != x[j * 2 + i - 1 - k]){fla = 0;break;}if (fla){flag = 0;cout << i << endl;break;}}}}
}

problem 1502

1502: C++通关考模拟题--KK看到了新闻

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 344  Solved: 227
[Submit][Status][Web Board]

description

KK最近看新闻,看到某石油公司计划建造一条由东向西的主输油管道。该管道要穿过一个有n 口油井的油田。从每口油井都要有一条输油管道沿最短路经(或南或北)与主管道相连。如果给定n口油井的位置,即它们的x 坐标(东西向)和y 坐标(南北向),应如何确定主管道的最优位置,即使各油井到主管道之间的输油管道长度总和最小的位置?KK想,这不就是给定n 口油井的位置,编程计算各油井到主管道之间的输油管道最小长度总和嘛。

input

输入由多组测试数据组成。每组测试数据输入的第1 行是油井数n,1≤n≤10000。接下来n 行是油井的位置,每行2个整数x和y,-10000≤x,y≤10000。

output

对应每组输入,输出的第1 行中的数是油井到主管道之间的输油管道最小长度总和。

Sample Input

5
1 2
2 2
1 3
3 -2
3 3

Sample Output

6

参考代码:

#include <bits/stdc++.h>
using namespace std;
int a[10010];
int main()
{int n;while (cin >> n){for (int i = 1; i <= n; i++){cin >> a[i];cin >> a[i];}int min = 0;for (int i = 2; i <= n; i++)min += abs(a[i] - a[1]);for (int i = 2; i <= n; i++){int s = 0;for (int j = 1; j <= n; j++){if (i != j)s += abs(a[i] - a[j]);}if (s < min)min = s;}cout << min << endl;}
}

problem 1503

1503: C++通关考模拟题--最大的三角形

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 382  Solved: 78
[Submit][Status][Web Board]

description

KK画了一个圆,圆心在原点,半径为R,然后她想要画一个三角形使得这个三角形的面积最大,KK现在只在圆上确定了一个点,请你帮她算出另外两个点的坐标。

input

首先输入一个正整数T代表有几组测试数据。每组测试数据包含这个点的x。y坐标。x*y不为0。

output

输出两个点的坐标,优先y小的,y相同时优先x相同的输出。输出保留三位小数。

Sample Input

1
3 5

Sample Output

2.830 -5.098 -5.830 0.098

参考代码:

​#include <bits/stdc++.h>using namespace std;
int main()
{int t;cin >> t;while (t--){double x, y;cin >> x >> y;double r = sqrt(x * x + y * y);double cos = sqrt(x * x / (x * x + y * y));double sin = sqrt(y * y / (x * x + y * y));if (x * y > 0)sin = -sin;double x0 = -x / 2;double y0 = -y / 2;double x1 = x0 + r * sin / 2 * sqrt(3), x2 = x0 - r * sin / 2 * sqrt(3);double y1 = y0 + r * cos / 2 * sqrt(3), y2 = y0 - r * cos / 2 * sqrt(3);if (y1 < y2)printf("%.3f %.3f %.3f %.3f\n", x1, y1, x2, y2);elseprintf("%.3f %.3f %.3f %.3f\n", x2, y2, x1, y1);}
}​

problem 1504

1504: C++通关考模拟题--KK的弹珠

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 160  Solved: 19
[Submit][Status][Web Board]

description

KK在收拾东西的时候找到了一个弹珠,她不禁玩了起来。KK在地上画了一个大大的圆形,半径为R。然后她又在圆的圆心处放了一个硬币,硬币的圆心与圆的圆心重叠,半径为Rr,弹珠撞到硬币会反弹。而弹珠的半径为r。KK想知道如果她弹了弹珠(弹珠严格在圆之外),弹珠会在大圆里面呆多少时间。为了便于计算,KK将原点设置为硬币圆心处,并给出了弹珠的初始坐标(x,y)以及速度向量(vx,vy),假设实验是理想的没有能量损耗的。

input

依次输入Rr,R,r,x,y,vx,vy。(可能有多次输入)

output

输出弹珠在大圆内呆的时间,保留三位小数

Sample Input

2 3 1 4 5 -1 -1

Sample Output

1.445

参考代码:

#include <bits/stdc++.h>
using namespace std;
double zg(double a, double b, double c)
{double deta = b * b - 4 * a * c;return (sqrt(deta) - b) / abs(2 * a);
}
double fg(double a, double b, double c)
{double deta = b * b - 4 * a * c;return (-sqrt(deta) - b) / abs(2 * a);
}
double deta(double a, double b, double c)
{return b * b - 4 * a * c;
}
int main()
{double Rr, R, r, x, y, vx, vy;while (cin >> Rr >> R >> r >> x >> y >> vx >> vy){double v = sqrt(vx * vx + vy * vy);double dis;double b, k;if (vx == 0)dis = abs(x);else{k = vy / vx;b = y - k * x;dis = abs(b) / sqrt(1 + k * k);}if (dis >= R + r){cout << "0.000\n";}else if (dis >= Rr + r){if (x * vx + y * vy >= 0)cout << "0.000\n";else{if (vx == 0)printf("%.3f\n", 2 * sqrt((R + r) * (R + r) - x * x) / v);elseprintf("%.3f\n", sqrt(deta(k * k + 1, 2 * k * b, b * b - (R + r) * (R + r))) / sqrt(k * k + 1) / v);}}else{if (x * vx + y * vy >= 0)cout << "0.000\n";else{if (vx == 0)printf("%.3f\n", 2 * (sqrt((R + r) * (R + r) - x * x) - sqrt((Rr + r) * (Rr + r) - x * x)) / v);else{double d1 = min(abs(zg(k * k + 1, 2 * k * b, b * b - (R + r) * (R + r)) - x), abs(fg(k * k + 1, 2 * k * b, b * b - (R + r) * (R + r)) - x));double d2 = min(abs(zg(k * k + 1, 2 * k * b, b * b - (Rr + r) * (Rr + r)) - x), abs(zg(k * k + 1, 2 * k * b, b * b - (Rr + r) * (Rr + r)) - x));printf("%.3f\n", 2 * (d2 - d1) * sqrt(k * k + 1) / v);}}}}
}

problem 1505

1505: C++通关考模拟题--Red and Black

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 164  Solved: 107
[Submit][Status][Web Board]

description

There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.

Write a program to count the number of black tiles which he can reach by repeating the moves described above.

input

The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.

There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.

'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)

output

For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).

Sample Input

 6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0 

Sample Output

45
59
6
13

参考代码:

#include <bits/stdc++.h>
using namespace std;
int n, m;
class pp
{
public:int x, y;
} a[500];
int dir[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
bool check(int x, int y)
{if (x < 1 || x > m || y < 1 || y > n)return 0;return 1;
}
int main()
{while (cin >> n >> m && n && m){char a[21][21];int vis[21][21];memset(vis, 0, sizeof(vis));pp start;for (int i = 1; i <= m; i++){for (int j = 1; j <= n; j++){cin >> a[i][j];if (a[i][j] == '@'){start.x = i;start.y = j;}}}vis[start.x][start.y] = 1;queue<pp> que;que.push(start);while (!que.empty()){pp now = que.front();que.pop();for (int i = 0; i < 4; i++){pp next;next.x = dir[i][0] + now.x;next.y = dir[i][1] + now.y;if (check(next.x, next.y) && vis[next.x][next.y] == 0 && a[next.x][next.y] == '.'){vis[next.x][next.y] = 1;que.push(next);}}}int sum = 0;for (int i = 1; i <= m; i++){for (int j = 1; j <= n; j++)if (vis[i][j])sum++;}cout << sum << endl;}
}

problem 1508

1508: C++通关考模拟题--最大公约数和最小公倍数

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1365  Solved: 643
[Submit][Status][Web Board]

description

小明刚学习了最大公约数和最小公倍数的知识,但是基础不够扎实,连下面的题都做不来。你能帮小明解决这个问题吗?

input

输入两个数a和b,(a>=1,b>=1,且都在int范围内)
当a == b == 0的时候结束输入

output

对应每组数据,输出a和b的最大公约数和最小公倍数之和

Sample Input

5 5
3 4
0 0

Sample Output

10
13

参考代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll a, ll b)
{ll c;while (a % b != 0){c = a % b;a = b;b = c;}return b;
}
int main()
{ll a;ll b;while (cin >> a >> b && a && b){cout << gcd(a, b) + a / gcd(a, b) * b << endl;}
}

problem 1510

1510: C++通关考模拟题--找不同

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 1210  Solved: 392
[Submit][Status][Web Board]

description

给你n串字符串,其中有一串和其它串不同。你能找出来吗?

input

第一行一个整数n。(n >= 3)
下面有n串字符串。(保证只有一串与其它不同)

output

输出不同的串

Sample Input

3
a a b

Sample Output

b

参考代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{int n;while (cin >> n){map<string, int> m;while (n--){string s;cin >> s;if (m.find(s) == m.end())m[s] = 1;elsem[s]++;}map<string, int>::iterator it = m.begin();for (; it != m.end(); it++){if (it->second == 1)cout << it->first << endl;}}
}

problem 1511

1511: C++通关考模拟题--平方和

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 961  Solved: 528
[Submit][Status][Web Board]

description

输出一个n,输出从1到n的所有数的平方和

input

输入一个n (1<=n<=1000)

output

输出计算的结果,由于结果会很大,请输出除以100009的余数

Sample Input

1
2

Sample Output

1
5

参考代码:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e5 + 9;
int main()
{int n;while (cin >> n){ll sum = 0;for (int i = 1; i <= n; i++)sum = (sum + i * i) % mod;cout << sum << endl;}
}

problem 1512

1512: C++通关考模拟题--英文算式

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 762  Solved: 106
[Submit][Status][Web Board]

description

给你一个英文算式,判断该算式的正确与否

input

每行一个英文的算式。数字用英文表示。比如12表示为one two每两个数字有空格。
有加减乘除四个操作(add,sub,mul,div),可能大小写会不一致。除法如果除不尽的话直接取整。
(题目降低了难度。保证每个操作数和结果大于等于0,小于等于9,即只有一位)
(保证每行的格式为 数的英文 操作的英文 数的英文 equal 数的英文)

output

如果该行正确,输出true
反之输出false

Sample Input

one add two equal three
two div one equal thRee
one add tWo equal three

Sample Output

true
false
true

参考代码:

#include <bits/stdc++.h>
using namespace std;
int f(string x)
{if (x == "zero")return 0;if (x == "one")return 1;if (x == "two")return 2;if (x == "three")return 3;if (x == "four")return 4;if (x == "five")return 5;if (x == "six")return 6;if (x == "seven")return 7;if (x == "eight")return 8;if (x == "nine")return 9;
}
string convert(string x)
{for (int i = 0; i < x.length(); i++){if (isupper(x[i]))x[i] = char(tolower(x[i]));}return x;
}
int main()
{string x;while (getline(cin, x)){stringstream sin(x);string s;vector<string> vv;int a1 = 0, a2 = 0, a3 = 0;int flag2 = 0, flag3 = 0;while (sin >> x){x = convert(x);if (x == "add"){flag3 = 1;continue;}if (x == "sub"){flag3 = 2;continue;}if (x == "mul"){flag3 = 3;continue;}if (x == "div"){flag3 = 4;continue;}if (x == "equal"){flag2 = 1;continue;}if (flag3 == 0)a1 = a1 * 10 + f(x);else{if (flag2 == 0)a2 = a2 * 10 + f(x);elsea3 = a3 * 10 + f(x);}}if ((flag3 == 1 && a1 + a2 == a3) || (flag3 == 2 && a1 - a2 == a3) || (flag3 == 3 && a1 * a2 == a3) || (flag3 == 4) && a2 != 0 && a1 / a2 == a3)cout << "true\n";elsecout << "false\n";}
}

problem 1513

1513: C++通关考模拟题--切掉哪个点1

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 316  Solved: 86
[Submit][Status][Web Board]

description

给你一颗树,书上有n个节点,问去掉哪个节点之后,树分成的块数最多。
(题目中保证树联通)

input

第一行输入一个n,代表结点的个数。(结点编号从1-n)
下面有n-1行,每行有两个数,代表两个节点相连。
当n等于0的时候结束。

output

对于每组样例,输出我们计算出的那个节点,如果两个节点相同,选择标号小的那个输出。

Sample Input

3
1 2
1 3
0

Sample Output

1

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{int n;while (cin >> n && n){map<int, int> m;n--;int t;while (n--){int x, y;cin >> x >> y;if (m.find(x) == m.end())m[x] = 1;elsem[x]++;if (m.find(y) == m.end())m[y] = 1;elsem[y]++;}map<int, int>::iterator it = m.begin();int ma = 0, id;for (; it != m.end(); it++){if (it->second > ma){ma = it->second;id = it->first;}}cout << id << endl;}
}

参考代码: 1515

1515: C++通关考模拟题--切掉哪个点2

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 235  Solved: 84
[Submit][Status][Web Board]

description

给你一棵树,树上有很多节点。有一些特殊的节点,它只和另外的一个节点相连,这种节点称为叶子。请问叶子有多少个?
(题目中保证树联通)

input

第一行输入一个n,代表结点的个数。(结点编号从1-n)
下面有n-1行,每行有两个数,代表两个节点相连。
当n等于0的时候结束。

output

对于每组样例,输出题中每棵树的叶子的个数。

Sample Input

3
1 2
2 3
0Sample Output
2

参考代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{int n;while (cin >> n && n){map<int, int> m;n--;int t;while (n--){int x, y;cin >> x >> y;if (m.find(x) == m.end())m[x] = 1;elsem[x]++;if (m.find(y) == m.end())m[y] = 1;elsem[y]++;}map<int, int>::iterator it = m.begin();int ma = 0, id;for (; it != m.end(); it++){if (it->second == 1){ma++;}}cout << ma << endl;}
}

prob 1516

1516: C++通关考模拟题--Calling Extraterrestrial Intelligence Again

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 230  Solved: 5
[Submit][Status][Web Board]

description

A message from humans to extraterrestrial intelligence was sent through the Arecibo radio telescope in Puerto Rico on the afternoon of Saturday November 16, 1974. The message consisted of 1679 bits and was meant to be translated to a rectangular picture with 23 * 73 pixels. Since both 23 and 73 are prime numbers, 23 * 73 is the unique possible size of the translated rectangular picture each edge of which is longer than 1 pixel. Of course, there was no guarantee that the receivers would try to translate the message to a rectangular picture. Even if they would, they might put the pixels into the rectangle incorrectly. The senders of the Arecibo message were optimistic.
We are planning a similar project. Your task in the project is to find the most suitable width and height of the translated rectangular picture. The term "most suitable" is defined as follows. An integer m greater than 4 is given. A positive fraction a / b less than or equal to 1 is also given. The area of the picture should not be greater than m. Both of the width and the height of the translated picture should be prime numbers. The ratio of the width to the height should not be less than a / b nor greater than 1. You should maximize the area of the picture under these constraints.

In other words, you will receive an integer m and a fraction a / b. It holds that m > 4 and 0 < a / b < 1. You should find the pair of prime numbers p, q such that pq <= m and a / b <= p / q <= 1, and furthermore, the product pq takes the maximum value among such pairs of two prime numbers. You should report p and q as the "most suitable" width and height of the translated picture.

input

The input is a sequence of at most 2000 triplets of positive integers, delimited by a space character in between. Each line contains a single triplet. The sequence is followed by a triplet of zeros, 0 0 0, which indicated the end of the input and should not be treated as data to be processed.

The integers of each input triplet are the integer m, the numerator a, and the denominator b described above, in this order. You may assume 4 < m <= 100000 and 1 <= a <= b <= 1000.

output

The output is a sequence of pairs of positive integers. The i-th output pair corresponds to the i-th input triplet. The integers of each output pair are the width p and the height q described above, in this order.

Each output line contains a single pair. A space character is put between the integers as a delimiter. No other characters should appear in the output.

Sample Input

 5 1 2
99999 999 999
1680 5 16
1970 1 1
2002 4 11
0 0 0 Sample Output
 2 2
313 313
23 73
43 43
37 53 

参考代码:

#include <bits/stdc++.h>
using namespace std;
int f(string x)
{int ans = 0;for (int i = 0; i < x.length(); i++)ans = ans * 10 + x[i] - '0';return ans;
}
int ans[10000][2];
vector<int> ss;
int main()
{for (int i = 2; i <= 100000; i++){bool flag = 1;for (int j = 2; j * j <= i; j++)if (i % j == 0){flag = 0;break;}if (flag){ss.push_back(i);}}string x;int m, a, b;int wcnm = 0;string ex[1000];while (getline(cin, x)){int kk = 1;stringstream sin(x);string t;while (sin >> t){if (kk == 1)m = f(t);if (kk == 2)a = f(t);if (kk == 3)b = f(t);kk++;}if (m == 0 && a == 0 && b == 0)break;wcnm++;ex[wcnm] = x;double k = b * 1.0 / a;int ma = 0;int flagi, flagj;for (int i = 0; i < ss.size() && ss[i] * ss[i] <= m; i++){for (int j = i; j < ss.size() && ss[i] * ss[j] <= m; j++){if (ss[j] * 1.0 / ss[i] <= k && ss[j] * ss[i] <= m && ss[j] * ss[i] > ma){ma = ss[j] * ss[i];flagi = ss[i];flagj = ss[j];}}}ans[wcnm][0] = flagi;ans[wcnm][1] = flagj;}if (ex[1][0] == ' ')for (int i = 1; i <= wcnm; i++){if (i == 1)cout << ' ';cout << ans[i][0] << ' ' << ans[i][1];if (i == wcnm)cout << " ";cout << endl;}else{for (int i = 1; i <= wcnm; i++)cout << ans[i][0] << ' ' << ans[i][1] << endl;}
}

ZJUT online OJ c++通关模拟题(problem1335-problem1516) 题解相关推荐

  1. I'm stuck! ccf模拟题。

    ccf模拟题. I'm stuck! 时间限制: 1.0s 内存限制: 256.0MB 问题描述 给定一个R行C列的地图,地图的每一个方格可能是'#', '+', '-', '|', '.', 'S' ...

  2. 重庆社区计算机考试题库,2020重庆社区工作者考试题库:模拟题100题(64)

    2020年重庆社区工作者考试正在如火如荼的开展,为了帮助大家做好备考工作,社区工作者考试模拟题,希望考生们能与小编共同坚持--每日一练! 2020年社区工作者考试模拟题100题64 1. 在市场经济条 ...

  3. 计算机一级考试模拟题函数,2015年计算机一级考试模拟题(四)

    2015年计算机一级考试模拟题(四) 请用Word 2003对考生文件夹下WORD.DOC文档中的文字进行编辑.排版和保存,具体要求如下: (1)将标题段("十年后的家电")文字设 ...

  4. java格林认证_Java考试格林模拟题

    Java考试格林模拟题 question 14) which of the following lines of code will compile without error 1) int i=0; ...

  5. 计算机应用a级考试,四川省职称计算机应用能力考试A级模拟题

    内容简介: 四川省职称计算机应用能力考试A级模拟题 一.单选题: 1.软件工程管理是指对(C)一切活动的管理. A.软件计划期 B.高级决策层 C.软件生命期 D.软件计划和开发期 2.从一个长度为n ...

  6. 1 23 456c语言,2014年计算机二级考试C语言模拟题(1)

    2014年计算机二级考试C语言模拟题(1) 21.下列程序的运行结果为( ). #include main() {struct date {int year,month,day; }today; pr ...

  7. Scratch青少年编程能力等级测试模拟题(四级)

    「青少年编程竞赛交流群」已成立(适合6至18周岁的青少年),公众号后台回复[Scratch]或[Python],即可进入.如果加入了之前的社群不需要重复加入. 我们将有关编程题目的教学视频已经发布到抖 ...

  8. 中国电子学会青少年编程能力等级测试图形化四级模拟题

    「青少年编程竞赛交流群」已成立(适合6至18周岁的青少年),公众号后台回复[Scratch]或[Python],即可进入.如果加入了之前的社群不需要重复加入. 我们将有关编程题目的教学视频已经发布到抖 ...

  9. Scratch青少年编程能力等级测试模拟题(三级)

    青少年编程竞赛交流群已成立(适合6至18周岁的青少年),公众号后台回复[Scratch]或[Python],即可进入.如果加入了之前的社群不需要重复加入. 微信后台回复"资料下载" ...

最新文章

  1. 代理模式和装饰者模式
  2. MATLAB reshape()函数和sub2ind()函数
  3. Spring Boot导出jar包发布
  4. boost::hof::unpack用法的测试程序
  5. COM编程入门---转发
  6. Vue—核心概念—异步组件和路由懒加载
  7. python requests库作用_python Requests库入门
  8. JAVA面试常考系列九
  9. django-模板渲染上下文context-0223
  10. 数字通信系统的主要性能指标
  11. /^(0|[1-9]\d*)([.]5)?$/ 在PHP正则中是什么意思 ?
  12. 【渝粤教育】国家开放大学2018年春季 8643-22T数据库基础与应用 参考试题
  13. java 高级调试_多种高级debug方法,帮你更快定位问题
  14. 拓端tecdat|R语言k-Shape时间序列聚类方法对股票价格时间序列聚类
  15. EMI的主要原因-共模电流
  16. ERROR: Maven JVM terminated unexpectedly with exit code 137
  17. MATLAB之极限、积分、微分
  18. 安全基线规范之Cisco核心交换机
  19. JS中数组(Array)、Json对象长度(length)获取方法
  20. jsp的两种开发模式

热门文章

  1. 揭秘IBM架构设计方法论 —— Solution Design I
  2. 使用 Power Query 制作工资条
  3. 接口开放平台,我的一些思考
  4. jquery前端简单分页_如何使用jQuery创建简单的分页
  5. android友盟微信分享到朋友圈,干货,Umeng分享纯图片(避免跳坑)到_微信,朋友圈等...
  6. Rcurl--炼数成金课程第一周
  7. 植物大战僵尸用户存档修改(CSDN任务1,20210418)
  8. 6.28(HTML2)
  9. 【stm32f429igt6】的WiFi模块数据收发。
  10. 关于tomcat下startup.bat双击闪退的问题