今天看到同学在准备pat,好奇做了一点试水。下面贴上部分代码~
1006
#include<iostream>
using namespace std;
int main(){
int n;
cin>>n;
int m=n;
int *a=new int [4];
int count=0;
int i=0;
while(m>0){
a[i]=m%10;
m=m/10;
i++;
count++;
}
if(n==0){
cout<<"0";
return 0;
}
if(count>=1){
if(count==2){
for(int i=0;i<a[1];i++)
{
cout<<"S";
}
for(int i=0;i<a[0];i++){
cout<<i+1;
}
cout<<endl;
}
else if(count==3)
{
for(int i=0;i<a[2];i++)
{
cout<<"B";
}
for(int i=0;i<a[1];i++)
{
cout<<"S";
}
for(int i=0;i<a[0];i++)
{
cout<<i+1;
}
cout<<endl;
}
else{
for(int i=0;i<a[0];i++)
{
cout<<i+1;
}
cout<<endl;
}
}
return 0;
}
1008
#include<iostream>
using namespace std;
int main(){
int m;
int n;
cin>>m>>n;
int *temp=new int[200];
for(int i=0;i<m;i++){
cin>>temp[i+100];
}
for(int i=99;i>=100-n;i--){
temp[i]=temp[i+m];
}
for(int i=100-n;i<100-n+m;i++){
if(i==100-n)
cout<<temp[i];
else
cout<<" "<<temp[i];
}
cout<<endl;
return 0;
}
1009
#include<iostream>
using namespace std;
#include<string>
int main(){
string *temp=new string[80];
int i=0;
while(cin){
cin>>temp[i];
i++;
if(cin.get()=='\n'){
cin.unget();
break;
}
}
for(int j=i-1;j>=0;j--){
if(j==i-1)
cout<<temp[j];
else
cout<<" "<<temp[j];
}
cout<<endl;
return 0;
}
1010
#include<iostream>
using namespace std;
int main() {
int xi;
int zhi;
int *temp = new int[1000];
int i0 = 0;
while (cin) {
cin >> temp[i0];
i0++;
if (cin.get() == '\n')
break;
}
int *output = new int[1000];
for (int i = 0; i + 1 <= i0; i = i + 2) {
if (temp[i + 1] != 0 && temp[i] != 0) {
output[i] = temp[i] * temp[i + 1];
output[i + 1] = temp[i + 1] - 1;
}
else if (temp[i + 1] == 0&&temp[i]==0)
{
output[i] = 0;
output[i + 1] = 0;
}
}
for (int i = 0; i<i0; i++) {
if(i%2==0&&temp[i]==0&&temp[i+1]==0)
{
if(i==0)
cout<<0<<" "<<0;
else
cout<<" "<<0<<" "<<0;
}
if (i % 2 == 0 && output[i] == 0) {
i++;
continue;
}
if (i == 0)
cout << output[i];
else
cout << " " << output[i];
}
cout << endl;
system("pause");
return 0;
}
1011
#include "stdafx.h"
#include<cmath>
#include<iostream>
using namespace std;
int main() {
long a;
long b;
long c;
int T;
cin >> T;
cin.get();
long **temp = new long*[10];
for (int i = 0; i < 10; i++) {
temp[i] = new long[3];
}
for (int i = 0; i<T; i++) {
cin >> temp[i][0] >> temp[i][1] >> temp[i][2];
}
for (int i = 0; i<T; i++) {
if (temp[i][0] + temp[i][1]>temp[i][2])
cout << "Case" << " " << "#" << i + 1 << ":" << " " << " " << "true" << endl;
else
cout << "Case" << " " << "#" << i + 1 << ":" << " " << " " << "false" << endl;
}
system("pause");
return 0;
}
1012
#include<iostream>
#include<iomanip>
using namespace std;
int main(){
int N;
int a1=a2=a3=a5=0;
double a4=0.0;
cin>>N;
cin.get();
int * temp=new int[1000];
int i=0;
while(cin){
cin>>temp[i];
i++;
}
int p=1;
int count=0;
int max=-1;
int flag=0;
for(int k=0;k<i-1;k++){
if(temp[k]%5==0&&temp[k]%2==0)
a1=a1+temp[k];
else if(temp[k]%5==1)
{
a2=a2+p*temp[k];
p=-1*p;
flag++;
}
else if(temp[k]%5==2){
a3++;
}
else if(temp[k]%5==3){
a4=a4+temp[k];
count++;
}
else if(temp[k]%5==4){
if(temp[k]>max)
max=temp[k];
}
}
if(a1>0) cout<<a1<<" ";
else cout<<"N"<<" ";
if(flag>0) cout<<a2<<" ";
else cout<<"N"<<" ";
cout<<a3;
if(count>0){
cout<<a4/count<<" ";
}
else cout<<"N"<<" ";
if (max>0)
cout<<max;
else cout<<"N";
cout<<endl;
return 0;
}
1013
#include<iostream>
#include<cmath>
using namespace std;
int main() {
int M;
int N;
cin >> M >> N;
int *temp = new int[10000];
int k = 0;
for (int i =2; k<=N; i++) { ??????无次数限制会错一个
int a = sqrt(i);
int flag = 0;
for (int j = 2; j <= a; j++) {
if (i%j == 0)
{
flag = 1;
}
}
if (flag == 0) {
temp[k] = i;
k++;
}
}
int lc = 0;
int s = 0;
for (int i =M-1; i < N; i++) {
if (s== 0)
cout << temp[i];
else
cout << " " << temp[i];
lc++;
s++;
if (lc % 10 == 0) {
cout << endl;
s = 0;
}
}
system("pause");
return 0;
}
1017
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
int main() {
string a,q;
int b,r;
cin >> a >> b;
int temp = a[0] - '0';
if (temp >= b) {
q.push_back(temp / b + '0');
}
for (int i = 1; i < a.length(); i++) {
r = temp%b;
temp = r * 10 + a[i] - '0';
q.push_back(temp / b + '0');
}
r = temp%b;
if (a.length() == 1 && a[0] - '0' < b)
{
cout << "0" << " " << a[0] - '0';
return 0;
}
else
{
cout << q << " " << r;
}
system("pause");
return 0;
}
1018
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
int N;
cin >> N;
char *a = new char[100000];
char *b = new char[100000];
for (int i = 0; i<N; i++) {
cin >> a[i] >> b[i];
}
int C1 = 0;
int J1 = 0;
int B1 = 0;
int C2 = 0;
int J2 = 0;
int B2 = 0;
int sh = 0;
int fu = 0;
int pin;
for (int i = 0; i<N; i++) {
if (a[i] == 'C'&&b[i] == 'J') {
sh++;
C1++;
}
else if (a[i] == 'J'&&b[i] == 'B') {
sh++;
J1++;
}
else if (a[i] == 'B'&&b[i] == 'C') {
sh++;
B1++;
}
else if (b[i] == 'C'&&a[i] == 'J') {
fu++;
C2++;
}
else if (b[i] == 'J'&&a[i] == 'B') {
fu++;
J2++;
}
else if (b[i] == 'B'&&a[i] == 'C') {
fu++;
B2++;
}
}
int max = 0;
char s;
if (max <=J1)
{
max = J1;
s = 'J';
}
if (max <=C1)
{
max = C1;
s = 'C';
}
if (max <=B1)
{
max = B1;
s = 'B';
}
max = 0;
char s2;
if (max <=J2)
{
max = J2;
s2 = 'J';
}
if (max <= C2)
{
max = C2;
s2 = 'C';
}
if (max <=B2)
{
max = B2;
s2 = 'B';
}
pin = N - sh - fu;
cout << sh << " " << pin << " " << fu << endl;
cout << fu << " " << pin << " " << sh << endl;
cout << s<< " " << s2;
system("pause");
return 0;
}
今天就做到这里啦~