#include<iostream>
using namespace std;
int main(){
//求解质因数
long long n,n2;
while (cin >> n){
n2 = n;
cout<<n<<"=";
for(int i = 2;i <= n;i++){
for(;n2 % i == 0;){
n2 = n2/i;
cout << i << "*";
}
}
cout<<"1" <<endl;
}
//求解最大公约数和最小公倍数
int m , n;
while ( cin >> m >> n)
{
cout << m << " ," << n ;
int temp1 = m * n;
if (m < n){
m ^= n;
n ^= m;
m ^= n;
}
int temp = 0;
while (1)
{
temp = m % n;
if (temp == 0){
cout << "最大公约数为: "<< n <<endl;
break;
}
m = n;
n = temp;
}
cout << "最小公倍数为: "<< temp1 / n <<endl;
}
// return 0;
//}
/*
题目描述
给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字:
A1 = 能被5整除的数字中所有偶数的和;
A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...;
A3 = 被5除后余2的数字的个数;
A4 = 被5除后余3的数字的平均数,精确到小数点后1位;
A5 = 被5除后余4的数字中最大数字。
输入描述:
每个输入包含1个测试用例。每个测试用例先给出一个不超过1000的正整数N,随后给出N个不超过1000的待分类的正整数。数字间以空格分隔。
输出描述:
对给定的N个正整数,按题目要求计算A1~A5并在一行中顺序输出。数字间以空格分隔,但行末不得有多余空格。
若其中某一类数字不存在,则在相应位置输出“N”。
输入例子:
13 1 2 3 4 5 6 7 8 9 10 20 16 18
输出例子:
30 11 2 9.7 9
*/
#include<iostream>
#include <iomanip>
#include<vector>
using namespace std;
int main(){
int N;
vector<int>array;
while (cin >> N){
for(int i = 0 ; i < N ;++i){
int temp;
cin >> temp;
array.push_back(temp);
}
break;
}
int A1 = 0;
int A2 = 0;
int sign = 1;
int A3 = 0;
int A4 = 0;
int count = 0;
int A5 = 0;
for (int i =0 ;i < array.size();++i){
if(array[i] % 5 == 0 && array[i]%2 ==0){
A1 += array[i];
continue;
}
if(array[i] % 5 == 1 ){
A2 += sign * array[i];
sign = -sign;
continue;
}
if(array[i] % 5 == 2){
++A3;
continue;
}
if(array[i] % 5 == 3){
A4 += array[i];
++count;
continue;
}
if(array[i] % 5 == 4){
if(array[i] > A5)
A5 = array[i];
continue;
}
}
if(A1 != 0 )
cout << A1 << " ";
else
cout << "N" <<" ";
if(A2 != 0 )
cout << A2 << " ";
else
cout << "N" <<" ";
if(A3 != 0 )
cout << A3 << " ";
else
cout << "N" <<" ";
if(A4 != 0 )
cout <<setiosflags(ios::fixed) << setprecision(1) << (1.0 *A4/count) << " ";
else
cout << "N" <<" ";
if(A5 != 0 )
cout << A5 << endl;
else
cout << "N" << endl;
return 0;
}
/*
令Pi表示第i个素数。现任给两个正整数M <= N <= 10000,请输出PM到PN的所有素数。
输入描述:
输入在一行中给出M和N,其间以空格分隔。
输出描述:
输出从PM到PN的所有素数,每10个数字占1行,其间以空格分隔,但行末不得有多余空格。
输入例子:
5 27
输出例子:
11 13 17 19 23 29 31 37 41 43
47 53 59 61 67 71 73 79 83 89
97 101 103
*/
#include<iostream>
#include<math.h>
using namespace std;
int main(){
unsigned int PM, PN;
cin >> PM >> PN;
if(PM > PN){
exit(-1);
}
unsigned int shusu[10001]={0};
int n =0 ;
int k = 0;
int count = 0;
unsigned int i = 0;
shusu[count++] = 2;
for(unsigned int m = 3; m <= 104729; m = m+2){
if(m == 1)
continue;
k = sqrt((double)m);
for( i = 2; i <= k ; ++i)
if(m % i == 0 )
break;
if(i > k )
shusu[count++] = m;
if (shusu[PN-1] != 0 ){
for (int j = PM-1; j< PN ;++j){
++n;
if(n % 10 == 0 ){
cout << shusu[j] << endl;
}
else if (j == PN-1)
cout << shusu[j];
else
cout << shusu[j] << " ";
}
break;
}
}
return 0;
}
/*
题目描述
大侦探福尔摩斯接到一张奇怪的字条:“我们约会吧! 3485djDkxh4hhGE 2984akDfkkkkggEdsb s&hgsfdk d&Hyscvnm”。大侦探很
快就明白了,字条上奇怪的乱码实际上就是约会的时间“星期四 14:04”,因为前面两字符串中第1对相同的大写英文字母(大小写有区分)是
第4个字母'D',代表星期四;第2对相同的字符是'E',那是第5个英文字母,代表一天里的第14个钟头(于是一天的0点到23点由数字0到9、
以及大写字母A到N表示);后面两字符串第1对相同的英文字母's'出现在第4个位置(从0开始计数)上,代表第4分钟。现给定两对字符串,
请帮助福尔摩斯解码得到约会的时间。
输入描述:
输入在4行中分别给出4个非空、不包含空格、且长度不超过60的字符串。
输出描述:
在一行中输出约会的时间,格式为“DAY HH:MM”,其中“DAY”是某星期的3字符缩写,即MON表示星期一,TUE表示星期二,WED表示星期三,THU表示星期
四,FRI表示星期五,SAT表示星期六,SUN表示星期日。题目输入保证每个测试存在唯一解。
输入例子:
3485djDkxh4hhGE
2984akDfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
输出例子:
THU 14:04
*/
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main(){
int T=4;
int i =0;
string str;
unsigned ihour = 0;
unsigned imin = 0;
bool flag = true;
vector<string> time(4);
while(T--)
cin >> time[i++];
for(int j =0;j < time[0].size() && j < time[1].size();++j){
if(time[0][j] == time[1][j] && time[0][j]>='A'
&& time[1][j]>='A'&& time[0][j]<='G'&& time[1][j]<='G' && flag ){
char temp = time[0][j];
switch(temp){
case 'A': str = "MON";
break;
case 'B': str = "TUE";
break;
case 'C': str = "WED";
break;
case 'D': str = "THU";
break;
case 'E': str = "FRI";
break;
case 'F': str = "SAT";
break;
case 'G': str = "SUN";
break;
default: break;
}
flag = false;
continue;
}
if(time[0][j] == time[1][j] && ((time[0][j]>='A'
&& time[1][j]>='A'&& time[0][j]<='N'&& time[1][j]<='N' ) ||
(time[0][j]>='0'
&& time[1][j]>='0'&& time[0][j]<='9'&& time[1][j]<='9')) && !flag){
char temp = time[0][j];
switch(temp){
case '0': ihour = 0;
break;
case '1': ihour = 1;
break;
case '2': ihour = 2;
break;
case '3': ihour = 3;
break;
case '4': ihour = 4;
break;
case '5': ihour = 5;
break;
case '6': ihour = 6;
break;
case '7': ihour = 7;
break;
case '8': ihour = 8;
break;
case '9': ihour = 9;
break;
case 'A': ihour = 10;
break;
case 'B': ihour = 11;
break;
case 'C': ihour = 12;
break;
case 'D': ihour = 13;
break;
case 'E': ihour = 14;
break;
case 'F': ihour = 15;
break;
case 'G': ihour = 16;
break;
case 'H': ihour = 17;
break;
case 'I': ihour = 18;
break;
case 'J': ihour = 19;
break;
case 'K': ihour = 20;
break;
case 'L': ihour = 21;
break;
case 'M': ihour = 22;
break;
case 'N': ihour = 22;
break;
default: break;
}
break;
}
}
for(int j =0; j < time[2].size() && j < time[3].size();++j)
if(time[2][j] == time[3][j] && time[2][j] >= 'a'&& time[3][j] >= 'a'&&
time[2][j] <= 'z' && time[3][j] <= 'z'){
imin = j;
break;
}
cout<< str << " ";
if(ihour <10)
cout << "0" << ihour << ":";
else
cout << ihour << ":";
if(imin < 10)
cout << "0" << imin << endl;
else
cout << imin <<endl;
return 0;
}
/*
3485djEkxh4hhGE
2984akEfkkkkggEdsb
s&hgsfdk
d&Hyscvnm
*/
/*
14 60 80
10000001 64 90
10000002 90 60
10000011 85 80
10000003 85 80
10000004 80 85
10000005 82 77
10000006 83 76
10000007 90 78
10000008 75 79
10000009 59 90
10000010 88 45
10000012 80 100
10000013 90 99
10000014 66 60
*/
#include<iostream>
#include<vector>
#include <algorithm>
using namespace std;
struct studentDate{
unsigned int textID;
unsigned int dgrade;
unsigned int cgrade;
};
bool compare(studentDate a, studentDate b){
if((a.dgrade+a.cgrade) > (b.dgrade+b.cgrade))
return true;
if((a.dgrade+a.cgrade) == (b.dgrade+b.cgrade) && a.dgrade > b.dgrade)
return true;
if(a.dgrade == b.dgrade && a.cgrade == b.cgrade && a.textID < b.textID)
return true;
return false;
}
int main(){
int people;
int dc_average;
int average;
cin >> people >> dc_average >> average;
vector<studentDate>sdate;
int i =0;
studentDate temp;
while(people--){
cin >> temp.textID;
cin >> temp.dgrade;
cin >> temp.cgrade;
sdate.push_back(temp);
}
vector<studentDate>sdateout;
for(int i =0 ; i < sdate.size();i++){
if(sdate[i].dgrade >= dc_average && sdate[i].cgrade >= dc_average)
sdateout.push_back(sdate[i]);
}
cout << sdateout.size()<< endl;
sort(sdateout.begin(),sdateout.end(),compare);
for(int i=0;i<sdateout.size();i++)
if(sdateout[i].dgrade >= average && sdateout[i].cgrade >= average)
cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
for(int i=0;i<sdateout.size();i++)
if(sdateout[i].dgrade >= average && sdateout[i].cgrade < average &&sdateout[i].cgrade >= dc_average)
cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
for(int i=0;i<sdateout.size();i++)
if(sdateout[i].dgrade < average && sdateout[i].dgrade >= dc_average && sdateout[i].cgrade < average && sdateout[i].cgrade >= dc_average &&
sdateout[i].dgrade >= sdateout[i].cgrade)
cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
for(int i=0;i<sdateout.size();i++)
if(sdateout[i].dgrade < average && sdateout[i].dgrade >= dc_average && sdateout[i].cgrade >= dc_average
&& sdateout[i].dgrade < sdateout[i].cgrade)
cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
//for(int i=0;i<sdateout.size();i++){
// if(sdateout[i].dgrade >= average && sdateout[i].cgrade >= average)
// cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
// else if(sdateout[i].dgrade >= average && sdateout[i].cgrade < average &&sdateout[i].cgrade >= dc_average)
// cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
// else if(sdateout[i].dgrade < average && sdateout[i].dgrade >= dc_average && sdateout[i].cgrade < average && sdateout[i].cgrade >= dc_average &&
// sdateout[i].dgrade >= sdateout[i].cgrade)
// cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
// else if(sdateout[i].dgrade < average && sdateout[i].dgrade >= dc_average && sdateout[i].cgrade >= dc_average
// && sdateout[i].dgrade < sdateout[i].cgrade)
// cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
// else
// cout << sdateout[i].textID << " " << sdateout[i].dgrade << " " << sdateout[i].cgrade << endl;
//}
return 0;
}
/*
正整数A的“DA(为1位整数)部分”定义为由A中所有DA组成的新整数PA。例如:给定A = 3862767,DA = 6,则A的“6部分”PA是66,因为A中有2个6。
现给定A、DA、B、DB,请编写程序计算PA + PB。
输入描述:
输入在一行中依次给出A、DA、B、DB,中间以空格分隔,其中0 < A, B < 1010。
输出描述:
在一行中输出PA + PB的值。
输入例子:
3862767 6 13530293 3
输出例子:
399
*/
#include<iostream>
using namespace std;
int main(){
long long A,B;
unsigned int DA,DB;
cin >> A >> DA >> B >> DB;
long long PA=0,PB=0;
int Atemp = A;
int Btemp = B;
while(Atemp){
if(Atemp % 10 == DA){
PA = 10*PA + DA;
}
Atemp /= 10;
}
while(Btemp){
if(Btemp % 10 == DB){
PB = 10*PB + DB;
}
Btemp /= 10;
}
cout << PA+PB <<endl;
return 0;
}
#include <iostream>
using namespace std;
int main(){
char a[100];
cin >> a;
cout <<strlen(a);
return 0;
}
/*
本题要求计算A/B,其中A是不超过1000位的正整数,B是1位正整数。你需要输出商数Q和余数R,使得A = B * Q + R成立。
输入描述:
输入在1行中依次给出A和B,中间以1空格分隔。
输出描述:
在1行中依次输出Q和R,中间以1空格分隔。
输入例子:
123456789050987654321 7
输出例子:
17636684150141093474 3
#include<iostream>
#include<string.h>
using namespace std;
int main(){
char A[1001];
char B;
char result[1001] = {0};
char resultemp;
int tempA = 0;
int tempB = 0;
int temp = 0;
cin >> A >> B;
int j =0;
for(int i = 0; i < strlen(A);++i){
if(A[i] >= B || temp != 0 ){
tempA = A[i] - '0';
tempB = B - '0';
resultemp = (temp*10+tempA) / tempB + '0';
result[j++] = resultemp;
temp = (temp*10+tempA) % tempB;
if (temp == 0)
continue;
}
else
{
if (temp == 0 && A[i] != '0'&& i != 0 ){ //考虑到80724023332
result[j++] = '0';
}
temp = (temp*10)+ A[i] - '0';
if (temp == 0 && A[i] == '0')
result[j++] = '0';
}
//if (temp == 0 && A[i] == '0'){
// result[j++] = '0';
//}
}
result[j] = '\0';
cout << result << " " << temp <<endl;
return 0;
}
//16920772951346726585949127791514269640807240233322765969599887194037278359358088887
PAT
最新推荐文章于 2022-04-08 18:18:16 发布