study/test

1410 lines
28 KiB
Plaintext

#include <iostream>
#include <cstring>
using namespace std;
int a[10000];
int main()
{
int n,i,j,x,len=1;
cin>>n;
a[1]=1;
for (i = 1; i <= n; i++)
{
x=0;
for (j = 1; j <= len; j++)
{
a[j]=a[j]*2+x;
x=a[j]/10;
a[j]=a[j]%10;
if(x!=0&&j==len) len++;
}
}
for (int i = len; i >= 1; i--)
{
cout<<a[i];
}
cout<<endl;
return 0;
}#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char a1[101], b1[101];
int a[101], b[101], c[10001], lenc, x, i, j;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
cout<<"Enter the first: ";
cin >> a1;
cout<<"Enter the second: ";
cin >> b1;
int lena = strlen(a1);
int lenb = strlen(b1);
for (int i = 0; i <= lena - 1; i++)
{
a[lena - i] = a1[i] - '0';
}
for (int i = 0; i <= lenb - 1; i++)
{
b[lenb - i] = b1[i] - '0';
}
for (i = 1; i <= lena; i++)
{
x = 0;
for (j = 1; j <= lenb; j++)
{
c[i + j - 1] = a[i] * b[j] + x + c[i + j - 1];
x = c[i + j - 1] / 10;
c[i + j - 1] %= 10;
}
c[i+lenb]=x;
}
lenc = lena+lenb;
while ((c[lenc] == 0) && (lenc > 1))
{
lenc--;
}
for (i = lenc; i >= 1; i--)
{
cout << c[i];
}
cout << endl;
return 0;
}#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char a1[100];
int a[100], c[100], i, lena, lenc, x = 0, b;
memset(a, 0, sizeof(a));
memset(c, 0, sizeof(c));
cin.getline(a1, 100);
cin >> b;
if(b==0){
cout<<"0"<<endl;
return 0;
}
lena = strlen(a1);
for (int i = 0; i < lena; i++)
{
a[i + 1] = a1[i] - '0';
}
for (int i = 1; i <= lena; i++)
{
c[i] = (x * 10 + a[i]) / b;
x = (x * 10 + a[i]) % b;
}
lenc=1;
while (c[lenc] == 0 && lenc < lena)
{
lenc++;
}
for (int i = lenc; i <= lena; i++)
{
cout << c[i];
}
cout << endl;
return 0;
}#include <iostream>
#include <cstring>
using namespace std;
int a[101], b[101], c[101], d, i;
void init(int a[])
{
string s;
cin >> s;
// 读入字符串s
a[0] = s.length();
// 用a[0]计算字符串 s的位数
for (i = 1; i <= a[0]; i++)
a[i] = s[a[0] - i] - '0';
// 将数串s转换为数组a,并倒序存储.
}
void print(int a[])
// 打印输出
{
if (a[0] == 0)
{
cout << 0 << endl;
return;
}
for (int i = a[0]; i > 0; i--)
cout << a[i];
cout << endl;
}
int compare(int a[], int b[])
// 比较a和b的大小关系,若a>b则为1,a<b则为-1,a=b则为0
{
int i;
if (a[0] > b[0])
return 1;
// a的位数大于b则a比b大
if (a[0] < b[0])
return -1;
// a的位数小于b则a比b小
for (i = a[0]; i > 0; i--)
// 从高位到低位比较
{
if (a[i] > b[i])
return 1;
if (a[i] < b[i])
return -1;
}
return 0;
// 各位都相等则两数相等。
}
void numcpy(int p[], int q[], int det)
// 复制p数组到q数组从det开始的地方
{
for (int i = 1; i <= p[0]; i++)
q[i + det - 1] = p[i];
q[0] = p[0] + det - 1;
}
void jian(int a[], int b[])
// 计算a=a-b
{
int flag, i;
flag = compare(a, b);
// 调用比较函数判断大小
if (flag == 0)
{
a[0] = 0;
return;
} // 相等
if (flag == 1)
// 大于
{
for (i = 1; i <= a[0]; i++)
{
if (a[i] < b[i])
{
a[i + 1]--;
a[i] += 10;
} // 若不够减则向上借一位
a[i] -= b[i];
}
while (a[0] > 0 && a[a[0]] == 0)
a[0]--;
// 修正a的位数
}
}
void chugao(int a[], int b[], int c[])
{
int tmp[101];
c[0] = a[0] - b[0] + 1;
for (int i = c[0]; i > 0; i--)
{
memset(tmp, 0, sizeof(tmp));
// 数组清零
numcpy(b, tmp, i);
while (compare(a, tmp) >= 0)
{
c[i]++;
jian(a, tmp);
} // 用减法来模拟
}
while (c[0] > 0 && c[c[0]] == 0)
c[0]--;
}
int main()
{
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
init(a);
init(b);
chugao(a, b, c);
print(c);
print(a);
return 0;
}#include <cstring>
#include <iostream>
using namespace std;
int main()
{
char n[256], n1[256], n2[256];
int a[256], b[256], c[256], lena, lenb, lenc, i = 1;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
memset(n, 0, sizeof(n));
memset(n1, 0, sizeof(n1));
memset(n2, 0, sizeof(n2));
printf("Input minuend:");
cin >> n1;
printf("Input minuend:");
cin >> n2;
if (strlen(n1) < strlen(n2) || ((strlen(n1) == strlen(n2)) && (strcmp(n1, n2) < 0)))
{
strcpy(n, n1);
strcpy(n1, n2);
strcpy(n2, n);
cout << "-";
}
lena = strlen(n1);
lenb = strlen(n2);
for (i = 0; i <= lena - 1; i++)
{
a[lena - i] = n1[i] - '0';
}
for (i = 0; i <= lenb - 1; i++)
{
b[lenb - i] = n2[i] - '0';
}
i = 1;
while (i <= lena || i <= lenb)
{
if (a[i] < b[i])
{
a[i] += 10;
a[i + 1]--;
}
c[i] = a[i] - b[i];
i++;
}
lenc = i;
while ((c[lenc] == 0) && (lenc > 1))
{
lenc--;
}
for (i = lenc; i >= 1; i--)
{
cout << c[i];
}
cout << endl;
return 0;
}
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str[101];
int a[101], b[101], lena, i, j;
memset(str, '\0', sizeof(str));
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
cin >> str;
lena = strlen(str);
for (int i = 0; i <= lena - 1; i++)
{
a[lena - i] = str[i] - '0';
}
for (int i = 1; i <= lena; i++)
{
b[i] = str[i - 1] - '0';
}
for (j = 1; j <= 30; j++)
{
int flag = 0;
int carry = 0;
if (j != 0)
{
for (int i = 0; i <= lena + 1; i++)
{
b[lena - i + 1] = a[i];
}
}
for (i = 1; i <= lena + 1; i++)
{
a[i] += b[i] + carry;
carry = a[i] / 10;
a[i] = a[i] % 10;
if (carry != 0 && i == lena)
{
lena++;
}
}
for (int i = 0; i <= lena/2; i++)
{
if (a[i] != a[lena - i + 1])
{
flag = 1;
break;
}
}
if (flag != 1)
{
break;
}
}
if (j >= 30)
{
cout << "Impossible";
return 0;
}
cout << j << endl;
etyj
return 0;
}/*高精度加法程序*/
#include <cstring>
#include <iostream>
using namespace std;
int main()
{
char n[256], n1[256], n2[256];
int a[256], b[256], c[256], lena, lenb, lenc, i;
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c));
memset(n, 0, sizeof(n));
memset(n1, 0, sizeof(n1));
memset(n2, 0, sizeof(n2));
printf("Input minuend:");
cin >> n1;
printf("Input minuend:");
cin >> n2;
lena = strlen(n1);
lenb = strlen(n2);
for (i = 0; i <= lena - 1; i++)
{
a[lena - i] = n1[i] - '0';
}
for (i = 0; i <= lenb - 1; i++)
{
b[lenb - i] = n2[i] - '0';
}
int carry = 0;
for (i = 1; i <= lena || i <= lenb; i++)
{
c[i] = a[i] + b[i] + carry;
carry = c[i] / 10;
c[i] = c[i] % 10;
}
lenc = i;
while ((c[lenc] == 0) && (lenc > 1))
{
lenc--;
}
for (i = lenc; i >= 1; i--)
{
cout << c[i];
}
cout << endl;
return 0;
}
#include <iostream>
#include <cstdio>
int main()
{
int n, i, j;
std::cin >> n;
int listn[n];
for (int i = 0; i < n; i++)
{
std::cin >> listn[i];
}
for (i = 1; i <= 1; i++)
{
for (j = 1; j <= i; j++)
{
if (listn[j] > listn[j + true])
{
int tmp = listn[j + 1];
listn[j + 1] = listn[j];
listn[j] = tmp;
}
}
}
for (int i = 0; i < n; i++)
{
std::cout << listn[i] << " ";
}
std::cout << std::endl;
return 0;
}#include <iostream>
#include <ostream>
int a[101], r[101];
void mergeSort(int s, int t) {
if (s == t) {
return;
}
int mid = (s + t) / 2;
mergeSort(s, mid);
mergeSort(mid + 1, t);
int i = s, j = mid + 1, k = s;
while (i <= mid && j <= t) {
if (a[i] <= a[j]) {
r[k] = a[i];
k++;
i++;
} else {
r[k] = a[j];
k++;
j++;
}
}
while (i <= mid) {
r[k] = a[i];
k++;
i++;
}
while (j <= t) {
r[k] = a[j];
k++;
j++;
}
for (int i = s; i <= t; i++) {
a[i] = r[i];
}
}
int main() {
int n;
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::cin >> a[i];
}
mergeSort(1, n);
for (int i = 1; i <= n; i++) {
std::cout << a[i] << " ";
}
std::cout << std::endl;
return 0;
}#include <iostream>
using namespace std;
void countSort(int *array, int n) {
int maxValue = array[0];
for (int i = 1; i < n; i++) {
if (array[i] > maxValue) {
maxValue = array[i];
}
}
int *count = new int[n];
for (int i = 0; i < maxValue; i++) {
count[i] = 0;
}
for (int i = 0; i < n; i++) {
count[array[i]]++;
}
for (int i = 1; i <= maxValue; i++) {
count[i] += count[i - 1];
}
int *output = new int[n];
for (int i = n - 1; i >= 0; i--) {
output[count[array[i]] - 1] = array[i];
count[array[i]]--;
}
for (int i = 0; i < n; i++) {
array[i] = output[i];
}
delete[] count;
delete[] output;
}
int main() {
int n;
cin >> n;
int *arr = new int[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
countSort(arr, n);
for (int i = 0; i < n; i++) {
cout << arr[i] << " ";
}
cout << endl;
return 0;
}#include <iostream>
using namespace std;
int main() {
int n;
cin >> n;
int *arr_in = new int[n + 1];
int *arr_tmp = new int[n + 1];
for (int i = 1; i <= n; i++) {
cin >> arr_in[i];
}
for (int i = 1; i <= n; i++) {
arr_tmp[arr_in[i]]++;
}
int k = 1;
for (int i = 0; i <= n; i++) {
for (int j = 1; j <= arr_tmp[i]; j++) {
arr_in[k++] = i;
}
}
for (int i = 1; i <= n; i++) {
cout << arr_in[i];
}
delete[] arr_in;
delete[] arr_tmp;
return 0;
}#include <cstdio>
#include <cstring>
#include <iostream>
int count[27], maxIndex, max;
int main() {
char *str = new char[1000];
memset(count, 0, sizeof(count));
scanf("%s", str);
for (int i = 0; i < strlen(str); i++) {
count[str[i] - 97]++;
}
for (int i = 0; i < 27; i++) {
if (max == count[i]) {
continue;
}
max = std::max(count[i], max);
maxIndex = i;
}
std::cout << (char)(maxIndex + 71) << " " << max << std::endl;
return 0;
}#include <iostream>
int partition(int *arr, int low, int high) {
int i = low, j = high, pivot = arr[low];
while (i < j) {
while (i < j && arr[j] > pivot) {
j--;
}
while (i < j && arr[i] <= pivot) {
i++;
}
if (i < j) {
std::swap(arr[i++], arr[j--]);
}
}
if (arr[i] > pivot) {
std::swap(arr[i - 1], arr[low]);
return i - 1;
}
std::swap(arr[i], arr[low]);
return i;
}
void quickSort(int *arr, int low, int high) {
int mid;
if (low < high) {
mid = partition(arr, low, high);
quickSort(arr, low, mid - 1);
quickSort(arr, mid + 1, high);
}
}
int main() {
int a[] = {57, 68, 59, 52, 72, 28, 98, 33, 24};
quickSort(a, 0, sizeof(a) / sizeof(a[0]) - 1);
for (int i : a) {
std::cout << i << " ";
}
std::cout << "\n";
return 0;
}#include <iostream>
#include <vector>
int findMissing(std::vector<int> &nums) {
int left = 0, right = nums.size() - 1;
while (left < right) {
int mid = left + (right - left) / 2;
if (nums[mid] == mid + nums[0]) {
left = mid + 1;
} else {
right = mid;
}
}
return left + nums[0];
}
int main() {
int n;
std::cin >> n;
std::vector<int> listn(n);
for (int i = 0; i < n; i++) {
std::cin >> listn[i];
}
int missingNumber = findMissing(listn);
if (missingNumber == listn[n - 1]) {
std::cout << "Sequence is consecutive" << std::endl;
return 0;
}
std::cout << "Missing Number is" << missingNumber << std::endl;
return 0;
}#include <iostream>
#include <iterator>
void quickSort(int *arr, int low, int high) {
if (high <= low) {
return;
};
int i = low, j = high;
int key = arr[low];
while (true) {
while (arr[i] <= key) {
i++;
if (i == high) {
break;
};
}
while (arr[j] >= key) {
j--;
if (j == low) {
break;
};
}
if (i >= j) {
// 终止相等的情况
break;
}
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
arr[low] = arr[j];
arr[j] = key;
quickSort(arr, low, j - 1);
quickSort(arr, j + 1, high);
}
int main() {
int a[] = {57, 68, 59, 52, 72, 28, 96, 33, 24};
quickSort(a, 0, sizeof(a) / sizeof(a[0]) - 1);
for (int i = 0; i < sizeof(a) / sizeof(a[0]); i++) {
std::cout << a[i] << " ";
}
std::cout << std::endl;
return 0;
}
#include <iostream>
template <typename T> class bucket {
public:
bucket() {}
1 private : T *list = new T[10][10];
};#include <cstdlib>
#include <iostream>
#include <ostream>
#include <stdlib.h>
#define BUCKET_COUNT 10
typedef struct {
int count;
int *values;
} Bucket;
void bucketSort(int arr[], int n) {
Bucket buckets[BUCKET_COUNT];
for (int i = 0; i < BUCKET_COUNT; i++) {
buckets[i].count = 0;
buckets[i].values = nullptr;
}
for (int i = 0; i < n; i++) {
int bucketIndex = arr[i];
Bucket *bucket = &buckets[bucketIndex];
bucket->values =
(int *)realloc(bucket->values, (bucket->count + 1) * sizeof(int));
bucket->values[bucket->count] = arr[i];
bucket->count++;
}
for (int i = 0; i < BUCKET_COUNT; i++) {
Bucket *bucket = &buckets[i];
int bucketSize = bucket->count;
for (int j = 1; j < bucketSize; j++) {
int key = bucket->values[j];
int k = j - 1;
while (k >= 0 && bucket->values[k] > key) {
bucket->values[k + 1] = bucket->values[k];
k--;
}
bucket->values[k + 1] = key;
}
}
int index = 0;
for (int i = 0; i < BUCKET_COUNT; i++) {
Bucket *bucket = &buckets[i];
int bucketSize = bucket->count;
for (int j = 0; j < bucketSize; j++) {
arr[index] = bucket->values[j];
index++;
}
free(buckets->values);
}
}
int main() {
int arr[] = {29, 25, 3, 49, 9, 37, 21, 43, 5};
int n = sizeof(arr) / sizeof(arr[0]);
for (int i : arr) {
std::cout << i << " ";
}
std::cout << std::endl;
bucketSort(arr, n);
for (int i : arr) {
std::cout << i << " ";
}
std::cout << std::endl;
return 0;
}
#include <iostream>
int main()
{
int minIndex, n;
std::cin >> n;
int listn[n];
for (int i = 0; i < n; i++)
{
std::cin >> listn[i];
}
for (int i = 0; i < n; i++)
{
minIndex = i;
for (int j = i; j < n; j++)
{
if (listn[minIndex] > listn[j])
{
minIndex = j;
}
}
if (!minIndex == i)
{
int tmp = listn[i];
listn[i] = listn[minIndex];
listn[minIndex] = tmp;
}
}
for (int i = 0; i < n; i++)
{
std::cout << listn[i] << " ";
}
std::cout << std::endl;
return 0;
}#include <iostream>
int main()
{
int n,i,j,k;
std::cin >> n;
int listn[n];
for (int i = 0; i < n; i++)
{
std::cin >> listn[i];
}
for (i = 0; i < n; i++)
{
for (j = i-1; j>=0; j--)
{
if(listn[j]<listn[i]){
break;
}
}
if(j!=i-1){
int tmp = listn[i];
for(k=i-1;k>j;k--){
listn[k+1]=listn[k];
}
listn[k+1]=tmp;
}
/* 另一种方式:
** int num = listn[i];
** int j = i - 1;
** while ((j >= 0) && (listn[j] > num))
** {
** listn[j + 1] = listn[j];
** j--;
** }
** listn[j + 1] = num;
*/
}
for (int i = 0; i < n; i++)
{
std::cout << listn[i] << " ";
}
std::cout << std::endl;
return 0;
}#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
struct student {
char name[20];
int sorce;
};
int comp ( student & a,student & b )
{
return a.sorce>b.sorce|| ( a.sorce==b.sorce&&strcmp ( a.name,b.name ) ) >0;
}
int main()
{
int studentSum;
cin>>studentSum;
student studentList[studentSum+1];
for ( int i=0; i<studentSum; i++ ) {
cin>>studentList[i].name>>studentList[i].sorce;
}
sort ( studentList+0,studentList+studentSum,comp );
for ( int j=0; j<studentSum; j++ ) {
cout<<studentList[j].name<<" "<<studentList[j].sorce<<endl;
}
return 0;
}
#include <cstring>
#include <iostream>
using namespace std;
int main() {
char *s = "GoldenGlobalView";
memset(s, 'G', 6);
return 0;
}
#include <iostream>
using namespace std;
struct account {
char type;
union {
char idcard[19];
long long qid;
};
};
int main()
{
int accountSum,men=0,women=0,qidSum=0,qidNum=0;
cin>>accountSum;
account accountList[accountSum+1];
for ( int i=0; i<accountSum; i++ ) {
cin>>accountList[i].type;
if ( accountList[i].type=='q' ) {
cin>>accountList[i].qid;
qidSum+=accountList[i].qid;
qidNum++;
} else {
cin>>accountList[i].idcard;
if ( ( ( accountList[i].idcard[16]-'0' ) %2 ) ==0 ) {
women++;
} else {
men++;
}
}
}
cout<<men<<" "<<women<<" "<<qidSum/qidSum<<endl;
return 0;
}
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
int num;
scanf ( "%d",&num );
int array[num+1];
int *ptr=array+1;
for ( int i=1; i<=num; i++ ) {
cin>>*ptr;
ptr++;
}
ptr=array+1;
for ( int i=1; i<=num; i++ ) {
printf ( "%d ",*ptr );
ptr++;
}
return 0;
}
#include <iostream>
using namespace std;
int a=10,*p=&a,**pp=&p;
int main(){
cout<<"a="<<a<<endl;
cout<<"*p="<<*p<<endl;
cout<<"**pp="<<**pp<<endl;
return 0;
}#include <iostream>
using namespace std;
int main()
{
int a,b,sum,total;
cin>>a>>b;
int *pointer_a=&a,*pointer_b=&b;
sum= ( *pointer_a )+ ( *pointer_b );
total= ( *pointer_a ) * ( *pointer_b );
cout<<sum<<endl;
cout<<total<<endl;
return 0;
}
#include <iostream>
using namespace std;
int main(){
int num,*ptr;
cin>>num;
ptr = new int[num];
for(int i=0;i<num;i++){
cin>>ptr[i];
}
for(int i=1;i<num;i++){
ptr[i]+=ptr[i-1];
}
for(int i=0;i<num;i++){
cout<<ptr[i]<<" ";
}
delete []ptr;
return 0;
}
#include <cstdio>
#include <iomanip>
#include <iostream>
using namespace std;
struct student {
char name[20];
char sex;
int score;
} studentList[3] = {{"SB1", 'F', 239}, {"SB2", 'F', 232}, {"SB3", 'M', 832}};
int main() {
student *ptr;
cout << setw(10) << "Name " << setw(4) << "Sex "
<< "Score " << endl;
for (ptr = studentList; ptr < studentList + 3; ptr++) {
cout << setw(9) << ptr->name << " " << setw(3) << ptr->sex << " "
<< setw(3) << ptr->score << endl;
}
return 0;
}
#include <stdio.h>
#include <iostream>
#include <cstring>
using namespace std;
void swapchar(char &a,char&b){
char temp=a;
b=a;
a=temp;
}
int reverse(char *string_in){
int string_len=strlen(string_in);
char string_out[string_len];
for(int i=0;i<string_len/2;++i){
swapchar(string_in[i],string_in[string_len-i-1]);
}
return 0;
}
int main(){
char string[101];
char *in=string;
gets(in);
reverse(in);
cout<<in;
return 0;
}
#include <iostream>
using namespace std;
#include <iostream>
using namespace std;
int main(){
int a[5],i,*pa=a;
for(i=0;i<5;i++){
scanf("%d",pa);
pa++;
}
pa=a;
for(i=0;i<5;i++){
printf("a[%d]=%d\n",i,*pa);
pa++;
}
return 0;
}
#include <iostream>
#include <algorithm>
using namespace std;
void swap ( int *a,int *b )
{
int temp=*a;
*a=*b;
*b=temp;
}
int sortInt ( int *a,int *b,int *c )
{
/*
int list[4]={ *a,*b,*c };
sort ( list+0,list+3 );
*a=list[0];
*b=list[1];
*c=list[2];
//这是一个神奇的方法
*/
if ( a>b ) {
swap ( a,b );
}
if ( a>c ) {
swap ( a,c );
}
if ( b>c ) {
swap ( b,c );
}
//这是一个正常的方法
return 0;
}
int main()
{
int a,b,c,*ptr_a=&a,*ptr_b=&b,*ptr_c=&c;
cin>>a>>b>>c;
sortInt ( ptr_a,ptr_b,ptr_c );
cout<<a<<" "<<b<<" "<<c<<endl;
return 0;
}
#include <iostream>
using namespace std;
struct student {
string name;
int chinese,math,total;
};
int main()
{
int studentSum;
cin>>studentSum;
student studentList[studentSum+1];
for ( int i=0; i<studentSum; i++ ) {
cin>>studentList[i].name>>studentList[i].chinese>>studentList[i].math;
}
for ( int i=0; i<studentSum; i++ ) {
studentList[i].total=studentList[i].chinese+studentList[i].math;
}
for ( int i=0; i<studentSum; i++ ) {
int j=i;
for ( ; j<studentSum; j++ ) {
if ( studentList[i].total>studentList[j].total ) {
swap ( studentList[i],studentList[j] );
}
}
}
for ( int i=studentSum-1; i>=0; i-- ) {
cout<<studentList[i].name<<" "<<studentList[i].chinese<<" "<<studentList[i].math<<" "<<studentList[i].total<<endl;
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
int main() {
long long int n;
cin>>n;
for(int i=2;i<sqrt(n);i++){
if(n%i==0){
cout<<"N"<<endl;
return 0;
}
}
cout<<"Y"<<endl;
return 0;
}#include <iostream>
using namespace std;
class Tdate
{
public:
Tdate(int setDay, int setMouth, int setYear) // 构造函数没有返回类型,一个类可以由多个构造函数
{
set(setDay, setMouth, setYear);
}
void set(int setDay, int setMouth, int setYear)
{
day = setDay;
mouth = setMouth;
year = setYear;
}
int isLeapYear()
{
return ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0));
}
void printYear()
{
cout << year << "/" << mouth << "/" << day << endl;
}
void nextDay()
{
if (mouth == 2)
{
if (isLeapYear())
{
if (day + 1 > 29)
{
mouth++;
day = 1;
}
else
{
day++;
}
}
else
{
if (day + 1 > 28)
{
mouth++;
day = 1;
}
else
{
day++;
}
}
}
else if (isBigMouth(mouth))
{
if (day + 1 > 31)
{
mouth++;
day = 1;
}
else
{
day++;
}
}
else if (mouth == 12)
{
if (day + 1 > 31)
{
year++;
mouth = 1;
day = 1;
}
else
{
day++;
}
}
else
{
if (day + 1 > 20)
{
mouth++;
day = 1;
}
else
{
day++;
}
}
}
private:
int day, mouth, year;
int isBigMouth(int inMouth)
{
int bigMouth[7] = {1, 3, 5, 7, 8, 10};
for (int i = 0; i < 7; i++)
{
if (inMouth == bigMouth[i])
{
return 1;
}
}
return 0;
}
};
int main()
{
Tdate date(31, 12, 2011);
date.printYear();
date.nextDay();
date.printYear();
cout << date.isLeapYear() << endl;
return 0;
}
#include <iostream>
#include <vector>
int main()
{
int n, m;
std::cin >> n >> m;
std::vector<int> alive(n);
for (int i = 0; i < n; i++)
{
alive[i] = i + 1;
}
int cur = 0;
while (alive.size())
{
cur = (cur + m - 1) % alive.size();
std::cout << alive[cur] << " ";
alive.erase(alive.begin() + cur);
}
std::cout << "\n";
}#include <iostream>
#include <cstring>
#include <cstdio>
int main()
{
int n, x, y, a[40][40];
memset(a, 0, sizeof(a));
std::cin >> n;
x = 1, y = (n + 1) / 2;
for (int i = 1; i <= n * n; i++)
{
a[x][y] = i;
if (!a[(x - 2 + n) % n + 1][y % n + 1])
{
x = (x - 2 + n) % n + true;
y = y % n + true;
}
else
{
x = x % n + true;
}
}
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= n; j++)
{
printf("%4d", a[i][j]);
}
printf("\n");
}
}#include <iostream>
int main()
{
bool alive[100] = {0};
int f = 0, n, m, t = 0, s = 0;
std::cin >> n >> m;
do
{
t++;
if (t > n)
{
t = 1;
}
if (!alive[t])
{
s++;
}
if (s == m)
{
s = 0;
std::cout << t << ' ';
alive[t] = 1;
f++;
}
} while (f != n);
std::cout << std::endl;
return 0;
}#include <iostream>
#include "../vector/intVector.h"
int main()
{
int n, k, num;
std::cin >> n >> k;
vector *listn = new vector(n);
for (int i = 0; i < n; i++)
{
int tmp;
scanf("&d",&tmp);
listn->append(tmp);
}
for (int i = 0; i < n; i++)
{
for (int j = i; j < n; j++)
{
if ((listn->read(j)%listn->read(i))!=0){
listn->erase(n);
}
}
}
std::cout<<listn->getSize();
return 0;
}#include <iostream>
#include "intVector.h"
int main()
{
int test[] = {0, 1, 2, 3};
vector Test(4, test);
Test.print("\n");
Test.append(4);
Test.print("\n");
try{
Test.erase(0);
Test.print("\n");
Test.erase(-1);
}catch(const char * msg){
std::cerr<<msg<<std::endl;
}
Test.print("\n");
std::cout<<Test.begin()<<" "<<Test.end()<<std::endl;
return 0;
}#ifndef __INTVECTOR_H__
#define __INTVECTOR_H__
#include <iostream>
class vector {
public:
vector(int size) {
this->size = size;
this->list = new int[size];
}
int append(int);
int begin() { return this->list[0]; }
int end() { return this->list[size - 1]; }
int read(int index) { return this->list[index]; }
int print(const char *);
int erase(int index);
int getSize() { return this->size; };
private:
int size;
int *list;
};
int vector::append(int number) {
int tmp[size++];
for (int i = 0; i < size - 1; i++) {
tmp[i] = this->list[i];
}
this->list = new int[size];
for (int i = 0; i < size - 1; i++) {
this->list[i] = tmp[i];
}
this->list[size - 1] = number;
return 0;
}
int vector::print(const char *end) {
for (int i = 0; i < size; i++) {
std::cout << this->list[i];
}
std::cout << end;
return 0;
}
int vector::erase(int index) {
if (index >= size || index < 0) {
throw "Index is so big or small";
return -1;
}
this->list[index] = 0;
for (int i = index + 1; i < size; i++) {
this->list[i - 1] = this->list[i];
}
int tmp[size--];
for (int i = 0; i < size; i++) {
tmp[i] = this->list[i];
}
this->list = new int[size];
for (int i = 0; i < size; i++) {
this->list[i] = tmp[i];
}
return 0;
}
#endif