//herizai_CD1第一题
#include<iostream>
#include<iomanip>
using namespace std; void print1(int n)//输出一个正三角形
{
for(int i=;i<=n;i++)//输出n行,第一行时i=1,第二行时i=2…对应下面每行*的个数
{
cout<<setw(-i)<<" ";//在*前打出30-i个空格来占位置,从而达到使*居中的目的,与for(k=0;k<30-i;k++) cout<<" "; 一样的效果。
for(int m=;m<*i;m++)//输出一行*, *的个数由循环次数i决定
{
cout<<"*";
}
cout<<endl; //输完一行后换行
}
} void print2(int n)//输出一个倒三角形
{
for(int i=n;i>;i--)//输出n行,第一行时i=1,第二行时i=2…对应下面每行*的个数
{
cout<<setw(-i)<<" ";//在*前打出30-i个空格来占位置,从而达到使*居中的目的,与for(k=0;k<30-i;k++) cout<<" "; 一样的效果。
for(int m=;m<*i;m++)//输出一行*, *的个数由循环次数i决定
{
cout<<"*";
}
cout<<endl; //输完一行后换行
}
} void print3(int n)//输出一个空心四边形
{
int i,j;
cout<<setw(n+); //录入字符个数a
for( i=;i<n;i++) //打印第一行a个‘*’
cout<<"*";
cout<<endl;
for(i=;i<n-;i++)
{
cout<<setw(n-i)<<"*"; //打印中间a-2行最左边的'*'
for(j=;j<n-;j++) //打印中间a-2行,第一行中的n-2个空白符
cout<<" ";
cout<<"*"; //打印中间a-2行最右边的'*'
cout<<endl;
}
cout<<" ";
for(i=;i<n;i++)
cout<<"*"; //打印最后一行a个‘*’
cout<<endl;
} void main()
{ char k;
int m=,choice;//m为三角形边长或是菱形的短对角线长
do
{
cout<<"请选择(1/2/3)\n 1 输出正三角形\n 2 输出倒三角形 \n 3 输出空心的平行四边形 \n 4返回";
cin>>choice;
switch(choice)
{
case :print1(m);break;
case :print2(m);break;
case :print3(m);break;//正三角形和倒三角形拼成的菱形
case :exit();
}
cout<<"是否继续(y/n)\n";
cin>>k;
}while(k=='y'||k=='Y');
}
 //herizai_CD2第二题
#include<iostream>
using namespace std;
void chengji(int Matrix[][])
{
int s=;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(i==j)
s*=Matrix[i][j];
cout<<"chengji is:"<<s<<endl;
} void sum(int Matrix[][])
{
int s=;
for(int i=;i<;i++)
for(int j=;j<;j++)
if(i==j)
s+=Matrix[i][j];
cout<<"The sum is:"<<s<<endl;
} void input(int Matrix[][])
{
for(int i=;i<;i++)
for(int j=;j<;j++)
cin>>Matrix[i][j];
}
void main()
{
int Matrix1[][],Matrix2[][],Matrix3[][];
int m;
cout<<"请选择(1/2/3)\n 1 输出Matrix1的主对角线乘积及和:\n 2 输出Matrix1的主对角线乘积及和:\n 3 输出Matrix1的主对角线乘积及和:\n 4返回";
cin>>m;
switch (m)
{
case :
input(Matrix1);
chengji(Matrix1);
sum(Matrix1);break;
case :
input(Matrix2);
chengji(Matrix2);
sum(Matrix2);break;
case :
input(Matrix3);
chengji(Matrix3);
sum(Matrix3);break;
default:
break;
}
}
 //herizai_CD2 题目4
#include<iostream>
#include<fstream>
using namespace std; int main()
{
ifstream in("Sfile.txt");
ofstream out("Dfile.txt");
string str;
for(int i=;i<str.length();i++)
in>>str[i];
int s=str.length();
for(int i=;i<s-;i++)
for(int j=i+;j<s;j++)
if(str[i>str[j]])
{
int temp=str[i];
str[i]=str[j];
str[j]=temp;
}
for(int k=;k<str.length();k++)
out<<str[k];
}
 //herizai_CD2_题目18
#include<iostream>
#include<string>
using namespace std;
char a(char b)
{
if(b>='a' && b<='z')
{
b=b-;
}
else if(b>='A' && b<='Z')
{
b=b+;
}
return b;
}
int main(void)
{
char s[];
char c;
int i;
gets(s);
for(i=;i<strlen(s);i++)
{
c=a(s[i]);
printf("%c",c);
} return ;
}
 //herizai_CD2_题目17
#include <iostream>
using namespace std;
int max(int a,int b)
{
if(b==)
return a;
else
return max(b,a%b);
}
void main()
{
int a,b;
cout<<"Input two numbers:"<<endl;
do
{
cin>>a>>b;
if(b<a)
cout<<"最大公约数为:"<<max(a,b)<<endl;
else
cout<<"最大公约数为:%d\n"<<max(b,a)<<endl;
cout<<"Input two numbers or input -999 to end:"<<endl;
}while(b!=(-)&&a!=(-));
}
 //herizai_CD2_题16
#include<iostream>
using namespace std;
int days(int nums);
void main()
{
int nums = ;
int day;
day = days(nums);
cout<<"卖完需要天数:"<<day<<endl;
}
int days(int nums)
{
int day=;
while(nums>)
{
int numsPerDay = nums/+ ;
nums=nums-numsPerDay;
day++;
}
return day;
}
 //herizai_CD2_题15
#include<iostream>
#include<string>
using namespace std;
int sumsquare(int n){
char s[],i;
int sum=;
sprintf(s,"%d",n);
for(i=;i<strlen(s);i++)//传过来的数使用sprintf()以字符串s体现,就是计算每一位数平方和,
sum += (s[i]-'')*(s[i]-'');//sum这个得到的就是这个传过来的数的平方和
return sum;
}
int hasamenum(int n){
char s[],i,j;
sprintf(s,"%d",n);
for(i=;i<strlen(s);i++)
for(j=i+;j<strlen(s);j++)
if(s[i]==s[j])
return ;
return ;
}
main()
{
int i;
for(i=;i<=;i++)
if(i / == sumsquare(i) && hasamenum(i))
printf("%d\n",i);
}
 //herizai_CD2_题目12
#include<iostream>
using namespace std;
int totalday(int year,int month,int day)//计算天数函数
{
int leap(int);//声明//一个函数的声明在另一个非main函数之中
int judge;
judge=leap(year);//调用
int total_day=;
month-=;
switch(month)
{
case :total_day+=;
case :total_day+=;
case :total_day+=;
case :total_day+=;
case :total_day+=;
case :total_day+=;
case :total_day+=;
case :total_day+=;
case :total_day+=;
case :judge?total_day+=:total_day+=;
case :total_day+=;
case :total_day+=day;break;
default :break;
}
return total_day;
} int leap(int year)//判断闰年函数
{
if(year%==&year%!=||year%==)
return ;
else
return ;
} int main()
{
int year,month,day;
cout<<"Please input year month day:"<<endl;
cin>>year>>month>>day;
cout<<"totalday is:"<<totalday(year,month,day)<<endl;
}
 //herizai_CD2_题目10
#include "stdio.h"
#include "time.h"
#include "dos.h"
#include "windows.h"
#include "string.h"
#include "ctype.h" int year_r(); //显示年
int month_h(); //月
int date_e(); //日
int time_e(); //时间
char * time_ta(); //将日期时间转换成字符串
int wait_t(); //延时1秒 char * time_ta() //将日期时间转换成字符串
{
char *q;
time_t t;
t=time(NULL);
q=ctime(&t);
//printf("*q_address = 0x%x\n",q);
return (q);
} int wait_t() //延时1秒
{
long temp_total=;
time_t time_temp;
time_temp=time(NULL);
temp_total=time_temp;
for(;;)
{
time_temp=time(NULL);
if(abs(time_temp - temp_total) >=)
break;
} return ();
} int main()
{
int temp; system("cls"); //清屏
printf("\n\n\n\n\n\n\n\n\t\t\t");
year_r();
printf("年");
temp = month_h();
if (temp != )
{
printf("%d",temp);
printf("月");
}
else printf("month error!\n");
date_e();
printf("日");
time_e();
printf("\r");
for(;;) //显示年月日时分秒
{
wait_t(); // 1秒钟到显示年月日时分秒
system("cls");
printf("\n\n\n\n\n\n\n\n\t\t\t");
year_r();
printf("年");
temp = month_h();
if (temp != )
{
printf("%d",temp);
printf("月");
}
else printf("month error!\n"); date_e();
printf("日");
time_e();
}
getchar(); } int year_r() //显示年
{ char *p;
int i;
p=time_ta();
for(i=;i<;i++,p++) //ctime函数返回字符为24个
if(i>&&i<)
printf("%c",*p);
return ();
} int month_h() //显示月
{
char month_n[][]={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
char *p;
char month[]; //存放三个字符
int i,j=;
p=time_ta();
for(i=;i<;i++,p++) //i<24因为ctime()函数返回有24个字符
{
if(i>= && i<) //取ctime函数返回值的第5--8共三个字符.
{
month[j++]=*p;
if(j==)
{
month[j]='\0';
break; }
}
}
for (i=;i<;i++)
{
if (strcmp(month_n[i],month) == )
{
return (i+); } } return (); } int date_e() //日
{
int j=,i=;
char date[];
char *p;
p=time_ta();
for(i=;i<;i++,p++)
if(i>=&&i<)
{ date[j]=*p;
printf("%c",date[j++]);}
return ;
} int time_e() //时间
{ int i;
char *p;
p=time_ta();
for(i=;i<;i++,p++)
if(i>&&i<)
printf("%c",*p);
printf("\n");
return ();
}
 //herizai_CD2_题目9
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int sum1=,sum2=,n=;
int month;
cin>>month;
if(month==||month==)
{
cout<<;
system("pause");
return ;
}
if(month%==)
{
month=month+;
n++;
}
for(int i=;i<month/;i++)
{
sum1=sum1+sum2;
sum2=sum1+sum2;
}
if(n==)
cout<<sum2;
if(n==)
cout<<sum1;
system("pause");
return ;
}
函数功能:把格式化的数据写入某个字符串
函数原型:int sprintf( char *buffer, const char *format [, argument] … );
返回值:字符串长度(strlen) 例子:
char* who = "I";
char* whom = "CSDN";
sprintf(s, "%s love %s.", who, whom); //产生:"I love CSDN. " 这字符串写到s中 sprintf(s, "%10.3f", 3.1415626); //产生:" 3.142"

herizai_CD2所做答案的更多相关文章

  1. NOI2010~NOI2018选做

    [NOI2010] [NOI2010]海拔 高度只需要0/1,所以一个合法方案就是一个割,平面图求最小割. [NOI2010]航空管制 反序拓扑排序,每次取出第一类限制最大的放置,这样做答案不会更劣. ...

  2. (C#) Tasks 中的异常处理(Exception Handling.)

    多线程编程中要注意对线程异常的处理.首先写个例子. 一个线程用于显示信息(Show Messages).主线程用于做其他工作(Do Works). using (Task taskShowMessag ...

  3. HDOJ-ACM1016(JAVA) 字典序全排列,并剪枝

    转载声明:原文转自http://www.cnblogs.com/xiezie/p/5576273.html 题意: 一个环是用图中所示的n个圆组成的.把自然数1.2.…….n分别放入每个圆中,并在相邻 ...

  4. 哪些产品不用开发原生APP,微信公众号就够了?

    最近一阶段H5技术被推到高峰,很多人认为借助H5就能利用微信公众号取代APP原生应用了,而事实是怎么样的?这里我从产品层做一个客观分析. 一,原生APP总体趋势 要谈APP是否会被微信取代,那么必须回 ...

  5. Codeforces.765F.Souvenirs(主席树)

    题目链接 看题解觉得非常眼熟,总感觉做过非常非常类似的题啊,就是想不起来=v=. 似乎是这道...也好像不是. \(Description\) 给定长为\(n\)的序列\(A_i\).\(m\)次询问 ...

  6. 【CF765F】Souvenirs 主席树

    [CF765F]Souvenirs 题意:给你一个长度为n的序列{ai},有m个询问,每次询问给出l,r,问在所有$l\le x < y\le r$中,$|a_x-a_y|$的最小值是多少. $ ...

  7. linux运维工程师面试题收集

    面试必考 mysql5和mysql6 有什么区别 mysql-server-5.5:默认引擎改为Innodb,提高了性能和扩展性,提高实用性(中继日志自动恢复) mysql-server-5.6:In ...

  8. iptables防火墙详解(一)

    -- 防火墙 常见的防火墙 :瑞星 江民 诺顿 卡巴斯基 天网...... iptables firewalld http://www.netfilter.org/ netfilter / iptab ...

  9. BZOJ.4453.cys就是要拿英魂!(后缀数组 单调栈)

    BZOJ 求字典序最大,容易想到对原串建后缀数组求\(rk\). 假设当前区间是\([l,r]\),对于在\([l,r]\)中的两个后缀\(i,j\)(\(i<j\)),显然我们不能直接比较\( ...

随机推荐

  1. grep 文本过滤

    1.命令功能 grep, egrep, fgrep - print lines matching a pattern 根据匹配模式空间(正则表达式)打印结果行. 2.语法格式 grep   [opti ...

  2. PCA 主成分分析

    链接1 链接2(原文地址) PCA的数学原理(转) PCA(Principal Component Analysis)是一种常用的数据分析方法.PCA通过线性变换将原始数据变换为一组各维度线性无关的表 ...

  3. tf Dataset API

    https://zhuanlan.zhihu.com/p/30751039 https://zhuanlan.zhihu.com/p/37106443 关于其中shuffle时的buffer_size ...

  4. 1125. Chain the Ropes (25)

    Given some segments of rope, you are supposed to chain them into one rope. Each time you may only fo ...

  5. Spring Boot整合Mybatis出现错误java.lang.IllegalStateException: Cannot load driver class:com.mysql.cj.jdbc.Driver

    错误描述: Caused by: java.lang.IllegalStateException: Cannot load driver class: com.mysql.cj.jdbc.Driver ...

  6. python中strftime和strptime函数

    strftime和strptime函数均来自包datetime from datetime import * strftime: 将datetime包中的datetime类,按照入参格式生成字符串变量 ...

  7. 如何解决MSVCR120.dll在Windows上缺少错误?

    在安装MySQL的时候,执行mysqld的时候,提示msvcr120.dll,是因为计算机中丢失了 一些文件 然后点击我下载完成安装就好了, 备注:两个都得安装!

  8. 通过form提交 django的安全机制

    通过form提交 在form表单里面需要添加{%csrf_token%} 这样当你查看页面源码的时候,可以看到form中有一个input是隐藏的 总结原理:当用户访问login页面的时候,会生成一个c ...

  9. 对webpack从零配置

    一.新建配置文件,文件名一般为webpack.config.js: 二.配置文件目录,一般为根目录,一般会放在./build文件夹下 三.配置文件格式一般为module.exports={}, 四.结 ...

  10. ubuntu16.04 下 C# mono开发环境搭建

    本文转自:https://www.cnblogs.com/2186009311CFF/p/9204031.html 前记 之前我一直不看好C#的前景,因为我认为它只能在windows下运行,不兼容,对 ...