一赞一道题 11.6-11.7
Posted BabiMonkey
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了一赞一道题 11.6-11.7相关的知识,希望对你有一定的参考价值。
flag一赞一道题代码
/*1001 害死人不偿命的(3n+1)猜想 (15 分)
#include<stdio.h>
int main() {
int n=0;
int i=0;
scanf_s("%d", &n);
while (n != 1) {
if (n % 2) {
n = (3 * n + 1) / 2;
}
else {
n = n / 2;
}
i++;
}
printf("%d", i);
return 0;
}
*/
/*1002 成绩排名 (20 分)#include<stdio.h>
int main() {
int n = 0;
int i, j;
scanf("%d", &n);
char Name[n][10];
}
#include<stdio.h>
int main() {
int n = 0;
int i, j;
int target1;
int target2;
scanf("%d", &n);
char Name[n][10];
char StdNum[n][10];
int Score[n];
for (i = 0; i < n; i++) {
scanf("%s", Name[i]);
scanf("%s", StdNum[i]);
scanf("%d", &Score[i]);
}
for (j = 0; j < n; j++) { //实现求最大值
int* max = NULL;
max = &Score[0];
if (Score[j] > *max) {
max = &Score[j];
target1 = j;
}
}
for (i = 0; i < n; i++) { //实现求最小值
int* min = NULL;
min = &Score[0];
if (Score[i] < *min) {
min = &Score[i];
target2 = i;
}
}
printf("%s", Name[i]);
printf("%s", StdNum[i]);
printf("%d", Score[i]);
printf("\\n");
printf("%s", Name[j]);
printf("%s", StdNum[j]);
printf("%d", Score[j]);
return 0;
}*/
//1003 继续(3n + 1)猜想(25 分)
/*#include<stdio.h>
#define N 1000
int main() {
int k;
scanf_s("%d", &k);
int i = 0;
int j = 0;
int target1 = 0;//比较数组的大小
int target2 = 0;
int n[N];
int temp = 0;
int Cmpare[N];
while (k != 1) {
if (k % 2) {
k = (3 * k + 1) / 2;
n[i] = k;
i++; target2++;
}
else {
k = k / 2;
n[i] = k;
i++; target2++;
}//得到标准数组
}
for (j = 0; j < N; j++) {
scanf_s("%d", Cmpare[j]);//输入比较数组
for (i = 0; i < target2; i++) {
if (Cmpare[j] = n[i]) {
Cmpare[target1] = n[j];
target1++;
}
}
}
for (i = 0; i < target1; i++) {
if (Cmpare[i] > Cmpare[i + 1]) {
temp = Cmpare[i];
Cmpare[i] = Cmpare[i + 1];
Cmpare[i + 1] = temp;
}
}
for (i = 0; i < target1; i++) {
printf("%d", Cmpare[i]);
}
return 0;
}*/
// 1004 换个格式输出整数(15 分)
/*
#include<stdio.h>
int main() {
int n;
scanf_s("%d", &n);
int B = 0;
int S = 0;
int G = 0;
B = n / 100;
S = n / 10-B*10;
G = n - S * 10-B*100;
while (B != 0) {
printf("B");
B--;
}
while (S != 0) {
printf("S");
S--;
}
int i = 1;
while (G != 0) {
printf("%d", i);
i++;
G--;
}
return 0;
}*/
//1005 素数对猜想 (20 分)
/*
#include<stdio.h>
#include<math.h>
int pan(int a)//判断素数
{
int index=1;
if(a<=1) index=0;
else{
for(int i=2; i<=sqrt(a); i++){//判断素数,直接判断2到根号a就OK
if(a%i==0)
index=0;
}
}
if(index==0){
return 0;
}else if(index==1){
return 1;
}
}
int main(void){
int n;
int cont=0;
scanf("%d",&n);
int a[10000];
int k=1;
for(int i=0; i<=n; i++){//把素数存到数组
if(pan(i)==1){
a[k]=i;
k++;
}
}
int cha;
for(int i=1; i<=k-1; i++){//找相邻的差为2的素数
cha=a[i+1]-a[i];
if(cha==2)
cont++;
}
printf("%d",cont);
return 0;
}
#include<stdio.h>
int main() {
int N;
scanf_s("%d", &N);
int i;
int j = 0;
int p[1000];
int target=0;
int Num=0;
for (i = 2; i < N; i++) {
for(j=0;j<N;j++){
while (i%2 == 1) {
p[j] = i;//素数表
target++;
}
}
}
for (i = 0; i < target; i++) {
if ((p[i + 1] - p[i]) % 2) {
Num++;
}
}
printf("%d", Num);
return 0;
}
*/
/*1006 数组元素循环右移问题
#include<stdio.h>
int main() {
int N = 0;//数组大小
scanf("%d", &N);
int n[N];//初始数组
int* p[N];
int i;//数组下标
p[0] = &n[0];
int j = 0;//
int M;
scanf_s("%d", &M);//向右平移单位
for (i = 0; i < N;i++) {
scanf("%d", &n[i]);
}//数组n[]的读入
for (j = 0; j < N - M; j++) {
p[j+M] = p[j];
}
i = 0;
while (j >= N - M) {
p[i] = p[j];
i++;
}
for (i = 0; i < N; i++) {
printf("%d",* p[i]);
}
return 0;
}
#include<stdio.h>
int main()
{
int len, move;
int i = 0;
scanf("%d%d", &len, &move);
int nums[len];
for (i = 0; i < len; i++) {
scanf("%d", &nums[i]);
}
move = move % len;
for (i = len - move; i < len; i++) {
printf("%d ", nums[i]);
}
for (i = 0; i < len - move; i++) {
if (i == len - move - 1)
printf("%d", nums[i]);
else
printf("%d ", nums[i]);
}
return 0;
}
*/
/*1007 shuzifenlei
#include<stdio.h>
int main() {
int N =8;
int n[8];
int i,j;
int A1 = 0;
int num1 = 0;//被5整除 所有偶数和
int A2= 0;
int num2 = 0;
int A3 = 0;
int num3 = 0;
int A4= 0;
int num4 = 0;
int A5 = 0;
int num5 = 0;
for (i = 0; i <= N; i++) {
scanf_s("%d", &n[i]);
}
for (i = 0; i < N; i++) {
while (n[i] % 5) {
A1 = A1+n[i];
num1++;
}
}
for (i = 0; i < N; i++) {
while (n[i] % 5 == 1) {
if (i == 0 || n[i] % 2) {
n[i] = -n[i];
num2++;
A2 = A2 + n[i];
}
}
}
for (i = 0; i < N; i++) {
while (n[i] % 5 == 2) {
num3++;
}
}
for (i = 0; i < N; i++) {
while (n[i] % 5 == 3) {
A3 = A3 + n[i];
num4++;
}
}
for (i = 0; i < N; i++) {
while (n[i] % 5 == 4) {
if (n[i] > A5) {
A5 = n[i];
}
}
}
if (num1== 0) {
printf("N");
}else{ printf("%d", A1 / num1); }
if (num2 == 0) {
printf("N");
}else{ printf("%d", A2); }
if (num3 == 0) {
printf("N");
}
else {
printf("%d", num3);
}
if (num4 == 0) {
printf("N");
}
else {
printf("%.1f", (double)A4/(double)num4);
}
if (num5 == 0) {
printf("N");
}
else {
printf("%d", A5);
}
return 0;
}*/
/*1008部分a+b*/
/*1009检查密码#include <iostream>
using namespace std;
int main() {
int N;
cin >> N;
getchar();
while (N--) {
string str;
getline(cin, str);
if (str.size() < 6) {
cout << "Your password is tai duan le." << endl;
}
else {
bool f1 = 0, f2 = 0, f3 = 0; //表示是否有字母或数字或不合法字符
for (unsigned i = 0; i < str.size(); i++) {
if (str[i] >= 'A' && str[i] <= 'Z' || str[i] >= 'a' && str[i] <= 'z') {
f1 = 1;
}
else if (str[i] >= '0' && str[i] <= '9') {
f2 = 1;
}
else if (str[i] == '.') {
continue;
}
else {
cout << "Your password is tai luan le." << endl;
f3 = 1;
break;
}
}
if (f3) { //有不合法字符且已输出
continue;
}
if (f1 && f2) {
cout << "Your password is wan mei." << endl;
}
else if (!f1) {
cout << "Your password needs zi mu." << endl;
}
else {
cout << "Your password needs shu zi." << endl;
}
}
}
return 0;
}
*/
/*1010小赌怡情
#include<stdio.h>
int main() {
int b, t;
int T; int K;
scanf("%d", &T);//输入初始筹码
scanf("%d", &K);//输入玩的次数
int n1[K];
int n2[K];
int i = 0;
int Km = K;
while (K > 0) {
scanf("%d %d %d %d", &n1[i], &b, &t, &n2[i]);//n1、n2游戏数据,b押宝,t筹码
i++;
K--;
}//输入游戏数据
for (i = 0; i < Km; i++) {
if (n1[i] > n2[i] && T >= t&&b==0) {
T = T + t;
printf("win %d! Total=%d\\n", t, T);
}
if (n1[i] < n2[i] && T >= t&&b==1) {
T = T - t;
printf("Lose %d. Total=%d\\n", t, T);
}
if (n1[i] > n2[i] && T >= t && b == 0) {
T = T - t;
printf("Lose %d. Total=%d\\n", t, T);
}
if (n1[i] < n2[i] && T >= t && b == 1) {
T = T + t;
printf("win %d! Total=%d\\n", t, T);
}
if (T < t) {
printf("Not enough tokens. Total = %d\\n", T);
}
if (T == 0) {
printf("Game Over.\\n");
break;
} //游戏过程
}return 0;
}
#include <stdio.h>
int main(){
int t,k,n1,b,c,n2,i;
scanf("%d %d",&t,&k);
for(i=0;i<k;i++){
scanf("%d %d %d %d",&n1,&b,&c,&n2);
if(c<=t){
if((b==0 && n2<n1) || (b==1 && n2>n1)){
t=t+c;
printf("Win %d! Total = %d.\\n",c,t);
}
else{
t=t-c;
printf("Lose %d. Total = %d.\\n",c,t);
if(t<=0){
printf("Game Over.\\n");
break;
}
}
}
else{
printf("Not enough tokens. Total = %d.\\n",t);
}
}
return 0;
}*/
/*1011个位数统计
#include<stdio.h>
int main() {
long int n;
scanf_s("%d", &n);
int Rnum = 0;
int a[10] = { 0,0,0,0,0,0,0,0,0,0 };
int i;//数组下标
while (n != 0) {
Rnum = n % 10;
n = n / 10;
switch(Rnum) {
case 0:
a[0]++;
break;
case 1:
a[1]++;
break;
case 2:
a[2]++;
break;
case 3:
a[3]++;
break;
case 4:
a[4]++;
break;
case 5:
a[5]++;
break;
case 6:
a[6]++;
break;
case 7:
a[7]++;
break;
case 8:
a[8]++;
break;
case 9:
a[9]++;
break;
default:;
}
}
for (i = 0; i<10; i++) {
if(a[i]!=0){
printf("%d:%d\\n", i, a[i]);
}
}
return 0;
}//520行代码 爱你哦*/
/* 1012跟奥巴马一起编程
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main()
{
int num, row;
char a;
scanf("%d %c", &num, &a);
if (num % 2 == 1)
{
row = (num + 1) / 2;
for (int i = 0; i < num; i++)
{
printf("%c", a);
}
printf("\\n");
for (int i = 0; i < row - 2; i++)
{
printf("%c", a);
for (int i = 0; i < num - 2; i++)
{
printf(" ");
}
printf("%c\\n", a);
}
for (int i = 0; i < num; i++)
{
printf("%c", a);
}
printf("\\n");
}
else
{
row = num / 2;
for (int i = 0; i < num; i++)
{
printf("%c", a);
}
printf("\\n");
for (int i = 0; i < row - 2; i++)
{
printf("%c", a);
for (int i = 0; i < num - 2; i++)
{
printf(" ");
}
printf("%c\\n", a);
}
for (int i = 0; i < num; i++)
{
printf("%c", a);
}
printf("\\n");
}
}
*/
/*1013 查验身份证
#include<stdio.h>
int main() {
int N;
scanf("%d", N);
int num[N][18];
int i;int j;int m;int n;
int Haven=0;
int p;
char Cmp[11] = { 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 };
int tar[] = { 7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2 };
for (j = 0; j < N; j++) {
for (i = 0; i < 18; i++) {
scanf("%d", &num[i]);
for (m = 0; m < 18; m++) {
n = 0;
Haven = Haven + num[m] * tar[n];
n++;
}
Haven = Haven % 11;//求出的权值
if (Haven == Cmp[Haven]) {
p++;//一个身份证核实正确
}
}//录入身份信息
}
if (p == N) {
printf("All passed");
}
else {
for (i = 0; i < N; i++) {
for (j = 0; j < 18; j++) {
printf("%d",num[j]);
}
}
}
return 0;
}
*/
/*1014快速排序
#include <stdio.h>
int cmp(const void* a, const void* b) {
return *(int*)a - *(int*)b;
}
int main() {
int n, max = 0, c = 0, i;
scanf("%d", &n);
int a[n], b[n], cn[n];
for (i = 0; i < n; i++) {
scanf("%d", &a[i]);
cn[i] = a[i];
}
qsort(cn, n, sizeof(cn[0]), cmp);
for (i = 0; i < n; i++) {
if (a[i] > max) max = a[i];
if (max == a[i] && a[i] == cn[i]) b[c++] = cn[i];
}
printf("%d\\n", c);
for (i = 0; i < c; i++) {
printf("%d", b[i]);
if (i != c - 1) printf(" ");
}
if (c == 0) printf("\\n");
return 0;
}
*/
/*1015划拳
#include<stdio.h>
int main() {
int n;
int Clon = 0;
scanf("%d", &n);
Clon = n;
int a[n][4];
int i, j;
int CupJia = 0; int CupYi = 0;//记录杯数
for (i = 0; i < Clon; i++) {
for (j = 0; j < 4; j++);
}//记录划拳数据
for (i = 0; i < Clon; i++) {
if (a[i][0] + a[i][2] == a[i][1] && a[i][1] == a[i][3]) {
CupYi++;
}
else if (a[i][0] + a[i][2] == a[i][3] && a[i][1] != a[i][3]) {
CupJia++;
}
else if (a[i][0] + a[i][2] == a[i][3] && a[i][3] != a[i][1]) {
;
}
else { ; }
}
printf("%d %d", CupJia, CupYi);
return 0;
}
*/
/*1016 统计同成绩学生 (20 分)
#include<stdio.h>
int main() {
int N;
int TarScore;
scanf("%d", &N);
int Score[N];
int i; int j;
for (i = 0; i < N; i++) {
scanf("%d", &Score[i]);
}//成绩表的输入
int TarNum = 0;
scanf("%d", &TarNum);//读入目标成绩数量
int Po[TarNum];//记录每个成绩的数量的数组
for (i = 0; i < TarNum; i++) {
scanf("%d", &TarScore);//读入目标成绩
for (j = 0; j < N; j++) {
if (Score[j] == TarScore) {
Po[i]++;
}
}
for (i = 0; i < TarNum; i++) {
printf("%d", Po[i]);
}
}
return 0;
}
#include"stdio.h"
int main(){
int n,m,a[101]={0},num;
int i;
scanf("%d",&m);
for(i=0;i<m;i++){
scanf("%d",&num);
a[num]++;
}
scanf("%d",&n);
for(i=0;i<n;i++){
scanf("%d",&num);
if(i!=0)
printf(" ");
printf("%d",a[num]);
}
return 0;
}
*/
/*1017判断题
#include<stdio.h>
int main() {
int M; int N;//N为学生总数,M为判断题数量;
scanf("%d %d", &M, &N);
int Haven[N];
int TA[M];
int i; int j;
int Score[N]; int TtalScore = 0;
for (i = 0; i < M; i++) {
scanf("%d", &Haven[i]);
}//权重数组
for (i = 0; i < M; i++) {
scanf("%d", &TA[i]);
}//正确答案数组
int SA[N][M];
for (j = 0; j < N; j++) {
for (i = 0; i < M; i++) {
scanf("%d", &SA[j][i]);
}
}//录入学生答案
for (i = 0; i < N; i++) {
for (j = 0; j < M; j++) {
if (SA[i][j] == TA[j]) {
TtalScore = TtalScore + Haven[j];
Score[i] = TtalScore;//第i个学生的成绩
}
}
}
for (i = 0; i < N; i++) {
printf("%d\\n", Score[i]);
}
return 0;
}*/
/*1018 考试座位号 (15 分)
#define maxn 1010
struct student {
long long id;//准考证号
int examSeat;//考试座位号
}testSeat[maxn];//试机座位号作为下标来记录考生
int main() {
int N;
int n, m, seat, examSeat;
long long id;
scanf("%d", &N);
for (int i = 0; i < N; i++) {
scanf("%lld %d %d", &id, &seat, &examSeat);//准考证号、试机座位号、考试座位号
testSeat[seat].id = id;
testSeat[seat].examSeat = examSeat;
}
scanf("%d", &m);//查询个数
for (int i = 0; i < m; i++) {
scanf("%d", &seat);
printf("%lld %d\\n", testSeat[seat].id, testSeat[seat].examSeat);
}
return 0;
}*/
/*图像过滤#include<stdio.h>
int main() {
int M; int N;// 像素
int A; int B;//待过滤灰度值
int target;//目标值
int i, j;//指针下标
scanf("%d %d", &M, &N);
scanf("%d %d", &A, &B);
scanf("%d", &target);
int Pic[10][10];
for (i = 0; i < M; i++) {
for (j = 0; j < N; j++) {
scanf("%d", &Pic[i][j]);
if (Pic[i][j] >= A && Pic[i][j] <= B) {
Pic[i][j] = 0;
}
}
}
for (i = 0; i < M; i++) {
for (j = 0; j < N; j++) {
if (j != N - 1) {
if (Pic[i][j] < 10) {
printf("00%d ", Pic[i][j]);
}
else if (Pic[i][j] < 100 && Pic[i][j] >= 10) {
printf("0%d ", Pic[i][j]);
}
else {
printf("%d ", Pic[i][j]);
}
}
else {
if (Pic[i][j] < 10) {
printf("00%d", Pic[i][j]);
}
else if (Pic[i][j] < 100 && Pic[i][j] >= 10) {
printf("0%d", Pic[i][j]);
}
else {
printf("%d", Pic[i][j]);
}
}
}
printf("\\n");
}
return 0;
}*/
/*1020 组合数的和 (15 分)#include<stdio.h>
int main() {
int N;
scanf("%d", &N);
int Num[N];
int i; int j;
int AdTion = 0;
for (i = 0; i < N; i++) {
scanf("%d", &Num[i]);
}//组合数数组
for (i = 0; i < N; i++) {
for (j = N-1; j >-1; i++) {
AdTion = Num[i] * 10 + Num[j] + Num[j] * 10 + Num[i];
}
}
printf("%d", AdTion);
return 0;
}*/
/*1021 N - 自守数(15 分)
#include <stdio.h>
#include <math.h>
int main()
{
int M, chengshu, ji, length, last, flag = 0;
int arr[20];
scanf("%d", &M);
for (int i = 0; i < M; i++)
{
scanf("%d", &arr[i]);
}
for (int j = 0; j < M; j++)
{
chengshu = 1;
length = 0;
int tmp = arr[j];
while (tmp > 0)
{
tmp /= 10;
length++;
}
while (chengshu < 10)
{
int k = 0;
last = 0;
ji = chengshu * arr[j] * arr[j];
int t = ji;
while (k < length)
{
last += pow(10, k) * (t % 10);
t /= 10;
k++;
}
if (last == arr[j])
{
printf("%d %d\\n", chengshu, ji);
flag = 1;
break;
}
flag = 0;
chengshu++;
}
if (flag == 0)
{
printf("No\\n");
}
}
return 0;
}*/
/*1022反转链表
#include <stdio.h>
typedef struct {
int address;//节点地址
int data; //整数数据
int next;//下一节点的地址
} Node;
int main() {
int addr, N, K;//读取首地址,节点数量,反转个数
scanf("%d %d %d", &addr, &N, &K);
Node origin[100001], sort[100001];//创建初始单链表,反转后的单链表
for (int i = 0; i < N; i++) {//读取节点
Node temp;
scanf("%d %d %d", &temp.address, &temp.data, &temp.next);
origin[temp.address] = temp;
}
for (int i = 0; i < N; i++) {//链接节点
sort[i] = origin[addr];
addr = sort[i].next;//获取下一个节点的地址
if (addr == -1) {
N = i + 1;//可能有无效的节点,需要更新链表中节点的数量
break;
}
}
for (int i = 0; i < N / K; i++) {//反转的次数
for (int j = 0; j < K / 2; j++) {//反转
Node temp;
temp = sort[j + i * K];
sort[j + i * K] = sort[K - 1 - j + i * K];//数组下标确认好
sort[K - 1 - j + i * K] = temp;
}
}
for (int i = 0; i < N; i++) {
if (i != N - 1) {
sort[i].next = sort[i + 1].address;
printf("%05d %d %05d\\n", sort[i].address, sort[i].data, sort[i].next);
}
else {
sort[i].next = -1;
printf("%05d %d %d\\n", sort[i].address, sort[i].data, sort[i].next);
}
}
return 0;
}
*/
/*1023wifi密码
#include<stdio.h>
int main()
{
int n, i, j;
char a, b, c;
scanf("%d", &n);
getchar();
for (i = 0; i < n; i++)
{
for (j = 0; j < 4; j++)
{
a = getchar();
getchar();//-
b = getchar();
getchar();//空格or回车
if (b == 'T')c = a;
}
printf("%d", c - 64);
}
printf("\\n");
return 0;
}*/
/*1024就不告诉你
#include<stdio.h>
int main() {
int m, n;
scanf("%d%d", &m, &n);
int tar = m * n;
while(tar!=0){
tar = tar % 10;
printf("%d", tar );
}
return 0;
}*/
/*1025有多少个不同的值
#include<stdio.h>
int main() {
int N;
scanf("%d", &N);
int i, j;
int n[N];
int n;
int num = 0;
n[0] = 0;
for (i = 1; i < N; i++) {
n = i / 2 + i / 3 + i / 5;
if (n[num] != n) {
n[num] = n;
num++;
}
}
printf("%d", num);
return 0;
}
*/
/*1026 组个最小数 (20 分)*/
#include <stdio.h>
int main() {
int n[10] = { 0 }, i;
for (i = 0; i < 10; i++) {//循环输入
scanf("%d", &n[i]);
}//对0的位数进行处理,如果有0,将后面个数不为0的数输出一个,并且该数个数减一
for (i = 1; i < 10; i++) {
if (n[i] != 0) break;
}
printf("%d", i);//输出第一位数
n[i]--;
for (i = 0; i < 10; i++) {//计算剩余位,直接输出
while (n[i] != 0) {
printf("%d", i);
n[i]--;
}
}
return 0;
}
/*1027人口普查
#include<stdio.h>
#include<string.h>
int main(){
int n,count=0,i;
scanf("%d",&n);//读入总数
int day,month,year;
char name[6],maxname[6],minname[6];//名字用字符数组存
long long maxage=20140906,minage=18140906;//不超两百年
for(i=0;i<n;i++){
scanf("%s %d/%d/%d",&name,&year,&month,&day);
long long birth=year*10000+month*100+day;//long long 型
if(birth<18140906 || birth>20140906);
else{//得到最年长和最年轻的人
count++;//记录有效生日的个数
if(birth < maxage){//找出最小的,最小的数即年龄最大的
strcpy(maxname,name);//strcpy函数,后面的存到前面的,name存到max_name
maxage=birth;
}
if(birth > minage){//得到最年轻
strcpy(minname,name);
minage=birth;
}
}
}
if(count){//只要不为0,就相当于真
printf("%d %s %s\\n",count,maxname,minname);
}else{
printf("0\\n");//这个点容易漏,即输入的都是不合理的数据
}
return 0;
}*/
/*1028 数字加密 (20 分
#include<stdio.h>
#include<string.h>
char A[105],B[105],word[3]={'J','Q','K'};
void reverse(char x[],int len){
int i,j;
char ch;
for(i=0,j=len-1;i<j;i++,j--){
ch=x[i];
x[i]=x[j];
x[j]=ch;
}
}
int main(){
int len1,len2,i,t1;
scanf("%s%s",A,B);
len1=strlen(A);
reverse(A,len1);
len2=strlen(B);
reverse(B,len2);
if(len1>len2){
for(i=len2;i<len1;i++){
B[i]='0';
}
len2=len1;
}
for(i=0;i<len1&&i<len2;i++){
if(i%2==0){
t1=((B[i]-'0')+(A[i]-'0'))%13;
}else{
t1=B[i]-A[i];
if(t1<0)
t1+=10;
}
if(t1>=10){
B[i]=word[t1-10];
}else{
B[i]=t1+'0';
}
}
reverse(B,len2);
printf("%s",B);
return 0;
}
*/
/*1029复数乘法
#include <stdio.h>
#include <math.h>
int main() {
double r1, p1, r2, p2;
double a, b;
scanf("%lf %lf %lf %lf", &r1, &p1, &r2, &p2);
a = r1 * r2 * cos(p1 + p2);
b = r1 * r2 * sin(p1 + p2);
if (fabs(a) < 0.01) a = 0;
if (fabs(b) < 0.01) b = 0;
printf("%.2lf%+.2lfi", a, b);
return 0;
}*/
/*1030 数素数 (20 分)
#include<stdio.h>
#include<math.h>
int issushu(int x)
{
for (int i = 2; i <=sqrt(x); i++)
{
if (x % i == 0)return 0;
}
return 1;
} //判断一个数是否是素数
int main()
{
int m = 0, n = 0, j = 0, k = 0;
int a[10001]; //用来放素数
scanf("%d %d", &m, &n);
for (int i = 2; j <= n; i++)
{
if (issushu(i))
{
a[++j] = i;
}
} // 一个一个判断是否是素数,若是放进数组,直到数组中素数个数达到N
for (int i = m; i <= n; i++)
{
printf("%d", a[i]);
if (++k % 10 != 0&&i!=n)printf(" ");
else printf("\\n");
} // 从第M个素数开始按格式输出
}*/
/*1031 狼人杀 - 简单版(20 分)
#include <stdio.h>
#include <stdlib.h>
int main() {
int N, i, j, k;
scanf("%d", &N);
int state[N + 1], identity[N + 1], Lier[N + 1], nLier;
for (i = 1; i <= N; i++) {
scanf("%d", &state[i]);
}
for (i = 1; i < N; i++) {
for (j = i + 1; j <= N; j++) {
for (k = 1; k <= N; k++) identity[k] = Lier[k] = 0;
identity[i] = identity[j] = 1, nLier = 0;
for (k = 1; k <= N && nLier <= 2; k++)
if (identity[abs(state[k])] != (state[k] < 0))
Lier[nLier++] = k;
if (nLier == 2 && identity[Lier[0]] + identity[Lier[1]] == 1) {
printf("%d %d", i, j);
return 0;
}
}
}
printf("No Solution");
}*/
/*1032求平均值
#include <iostream>
#include <cstdio>
#include <string.h>
using namespace std;
int main() {
int n, cnt = 0;
char a[50], b[50];
double temp = 0.0, sum = 0.0;
cin >> n;
for(int i = 0; i < n; i++) {
scanf("%s", a);
sscanf(a, "%lf", &temp);
sprintf(b, "%.2f",temp);
int flag = 0;
for(int j = 0; j < strlen(a); j++)
if(a[j] != b[j]) flag = 1;
if(flag || temp < -1000 || temp > 1000) {
printf("ERROR: %s is not a legal number\\n", a);
continue;
} else {
sum += temp;
cnt++;
}
}
if(cnt == 1)
printf("The average of 1 number is %.2f", sum);
else if(cnt > 1)
printf("The average of %d numbers is %.2f", cnt, sum / cnt);
else
printf("The average of 0 numbers is Undefined");
return 0;
}*/
/*1033朋友数
#include <stdio.h>
int main(){
int n,i,sum,count,m;
scanf("%d",&n);
int num[37]={0};
for(i=0;i<n;i++){
scanf("%d",&m);
for(sum=0;m;m=m/10){
sum += m % 10;
}
if(!num[sum]){
num[sum]=1,count++;
}
}
printf("%d\\n",count);
for(i=1;i<37;i++){
if(num[i]){
printf("%d%c",i,--count?' ':'\\0');
}
}
return 0;
}
*/
/*1034是否存在相等的差
#include <stdio.h>
int main() {
int i, n, num, arr[10000] = { 0 };
scanf("%d", &n);
for (i = 0; i < n; i++) {
scanf("%d", &num);
arr[(num > i + 1) ? (num - i - 1) : (i + 1 - num)]++;
}
for (i = n - 1; i >= 0; i--) {//从大到小输出重复的差值及其重复的次数
if (arr[i] >= 2) {
printf("%d %d\\n", i, arr[i]);
}
}
return 0;
}
*/
/*1035打印沙漏
#include <stdio.h>
#include <math.h>//调用sqrt()函数的头文件
int main(){
int n,i,j;
char c;
scanf("%d %c",&n,&c);//读入数和字符
int chu=(int)sqrt(2.0*(n+1))-1;//最多的一行的个数,sqrt()计算一个非负实数的平方根
if(chu%2==0) chu--;//保证每行输出奇数个
int sum=(chu+1)*(chu+1)/2-1;//所需总数
for(i=chu;i>=1;i=i-2){//输出上面的部分
for(j=0;j<(chu-i)/2;j++){
printf(" ");
}
for(j=0;j<i;j++){
printf("%c",c);
}
printf("\\n");
}
for(i=3;i<=chu;i=i+2){//输出下面的部分
for(j=0;j<(chu-i)/2;j++){
printf(" ");
}
for(j=0;j<i;j++){
printf("%c",c);
}
printf("\\n");
}
printf("%d\\n",n-sum);//输出多余的符号数
return 0;
} */
/*1036说反话
#include <stdio.h>
#include <stdlib.h>
int main()
{
char a[81][81] = { '\\0' };
int i = 0, j;
do
{
scanf("%s", a[i]);
i++;
} while (getchar() != '\\n');
for (j = i - 1; j > 0; j--)
{
printf("%s ", a[j]);
}
printf("%s\\n", a[j]);
return 0;
}*/
/*1037数字黑洞
#include <stdio.h>
int cap(const void *a, const void *b){
return *(int*)b - *(int*)a;
}
int stor(int n){
int zoo[4] = {n/1000, n%1000/100, n%100/10, n%10};
qsort(zoo, 4, sizeof(int), cap);
return zoo[0] * 1000 + zoo[1] * 100 + zoo[2] * 10 + zoo[3];
}
int rever(int n){
return n/1000 + n%1000/100 * 10 + n%100/10 * 100 + n%10 * 1000;
}
int main(){
int n;
scanf("%d", &n);
do{
n = stor(n);
printf("%04d - %04d = %04d\\n", n, rever(n), n - rever(n));
n = n - rever(n);
}while(n != 0 && n != 6174) ;
return 0;
}*/
//1038数列的片段和 (20 分)
/*//1049
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdlib.h>
using namespace std;
int main()
{
long n;//题中说10的5次方,所以int是不够用的,这就是测试点23的错误原因
cin >> n;
int times = n;
double result = 0, temp;
for (long i = 0; i < n; i++)
{
cin >> temp;
result += times *(n+1-times)* temp;
times--;
}
printf("%.2f", result);
system("pause");
return 0;
}
*/
/*1039程序运行时间
#include <stdio.h>
int main(){
int c1,c2,sum;
scanf("%d %d",&c1,&c2);
int hh,mm,ss;
sum=(c2-c1+50)/100;
ss=sum%60;
mm=sum%3600/60;
hh=sum/3600;
printf("%02d:%02d:%02d",hh,mm,ss);
return 0;
}*/
//1040插入与归并
#include <stdio.h>
#include <stdlib.h>
int comp(const void* a, const void* b)
{
return *(int*)a - *(int*)b;
}
int main()
{
int N, origin[100], halfsort[100], i, j, length;
scanf("%d", &N);
for (int i = 0; i < N; i++) scanf("%d", origin + i);
for (int i = 0; i < N; i++) scanf("%d", halfsort + i);
/* if it is insertion sort, return sorted length if yes, zero otherwise */
for (i = 0; i < N - 1 && halfsort[i] <= halfsort[i + 1]; i++);
for (length = ++i; i < N && halfsort[i] == origin[i]; i++);
length = i == N ? length + 1 : 0;
if (length) /* insertion sort */
{
puts("Insertion Sort");
qsort(origin, length, sizeof(int), comp);
}
else /* merge sort, operate on the original array */
{
puts("Merge Sort");
for (length = 1, i = 0; i < N && length <= N; length *= 2)
{
/* i == N means identical, also breaks the outer 'for' loop */
for (i = 0; i < N && origin[i] == halfsort[i]; i++);
for (j = 0; j < N / length; j++)
qsort(origin + j * length, length, sizeof(int), comp);
qsort(origin + j * length, N % length, sizeof(int), comp);
}
}
for (int i = 0; i < N; i++)
printf("%d%c", origin[i], i == N - 1 ? '\\n' : ' ');
return 0;
}
//over good night
以上是关于一赞一道题 11.6-11.7的主要内容,如果未能解决你的问题,请参考以下文章
Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段