继上一个系列,这里给出第二个系列的题解。 这里改变一下,分别给出来。持续更新中.....
题目来源:http://acm.hdu.edu.cn/listproblem.php?vol=11 中2021~2050
题解code如下:
#2021:算工资:除数和余数的判断
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2021
#include <iostream>
#include <cstdio>
using namespace std;
int n,num,sum;
int main(){
while(scanf("%d",&n)!=EOF && n){
sum=0;
for(int i=1;i<=n;i++){
scanf("%d",&num);
sum+=num/100;
num%=100;
sum+=num/50;
num%=50;
sum+=num/10;
num%=10;
sum+=num/5;
num%=5;
sum+=num/2;
num%=2;
sum+=num;
}
printf("%d\n",sum);
}
return 0;
}
#2022:找出绝对值最大的值以及坐标
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2022
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 1000;
int n,m,maxn,x,y;
int arr[MAXN][MAXN];
int abs(int x){return x>0?x:-x;}
int main(){
while(scanf("%d%d",&m,&n)!=EOF){
maxn=0;
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++){
scanf("%d",&arr[i][j]);
if(abs(maxn)<abs(arr[i][j])){
maxn=arr[i][j];
x=i;y=j;
}
}
printf("%d %d %d\n",x,y,maxn);
}
return 0;
}
#2023:求平均成绩
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2023
#include <iostream>
#include <cstdio>
using namespace std;
const int MAXN = 50;
int n,m,num;
double savg,cavg,avg[MAXN];
int arr[MAXN][5];
int main(){
while(scanf("%d%d",&n,&m)!=EOF){
int flag=0,k=0,count=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
scanf("%d",&arr[i][j]);
for(int i=1;i<=n;i++){
savg=0;
for(int j=1;j<=m;j++)
savg+=arr[i][j];
if(!flag){printf("%.2lf",savg/m);flag=1;}
else
printf(" %.2lf",savg/m);
}
printf("\n");
for(int i=1;i<=m;i++){
cavg=0;
for(int j=1;j<=n;j++)
cavg+=arr[j][i];
avg[++k]=cavg/n;
if(flag){printf("%.2lf",cavg/n);flag=0;}
else
printf(" %.2lf",cavg/n);
}
printf("\n");
for(int i=1;i<=n;i++){
flag=0;k=0;
for(int j=1;j<=m;j++)
if(arr[i][j]<avg[++k]){flag=1;break;}
if(!flag) count++;
}
printf("%d\n\n",count);
}
return 0;
}
#2024:判断变量命名是否合法
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2024
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 50+5;
char str[MAXN];
int n;
bool flag;
int main(){
scanf("%d",&n);
getchar();
while(n--){
gets(str);
int len=strlen(str);
if((str[0]>='a' && str[0]<='z') || (str[0]>='A' && str[0]<='Z') || str[0]=='_'){
for(int i=1;i<len;i++){
if((str[i]>='0' && str[i]<='9')||(str[i]>='a' && str[i]<='z') || (str[i]>='A' && str[i]<='Z') || str[i]=='_')
flag=1;
else{
flag=0;
break;
}
}
if(flag) printf("yes\n");
else printf("no\n");
}
else{
printf("no\n");
continue;
}
}
return 0;
}
#2025:加上特定子串
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2025
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
string str;
string arr="(max)";
char ch;
int pos;
int main(){
while(cin>>str){
ch=str[0];
int len=str.size();
for(int i=len-1;i>=0;i--)
if(str[i]>ch)
ch=str[i];
for(int i=0;i<len;i++){
cout<<str[i];
if(str[i]==ch) cout<<arr;
}
cout<<endl;
}
return 0;
}
#2026:首字母变为大写
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2026
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100;
char str[MAXN];
int main(){
while(gets(str)){
int len=strlen(str);
if(str[0]!=' ')str[0]-=32;//也可直接使用封装函数toupper()来转换大小写
for(int i=1;i<len;i++){
if(str[i-1]==' '&&str[i]!=' ') str[i]-=32;
}
for(int i=0;str[i]!='\0';i++) //这里需要判断下,不然OLE
cout<<str[i];
cout<<endl;
}
return 0;
}
#2027:统计元音个数
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2027
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 101;
char str[MAXN];
int numa,nume,numi,numo,numu;
int t;
int main(){
scanf("%d",&t);
getchar();
while(t--){
gets(str);
numa=nume=numi=numo=numu=0;
int len=strlen(str);
for(int i=0;i<len;i++){
if(str[i]=='a') numa++;
if(str[i]=='e') nume++;
if(str[i]=='i') numi++;
if(str[i]=='o') numo++;
if(str[i]=='u') numu++;
}
cout<<"a:"<<numa<<endl;
cout<<"e:"<<nume<<endl;
cout<<"i:"<<numi<<endl;
cout<<"o:"<<numo<<endl;
cout<<"u:"<<numu<<endl;
if(t) cout<<endl;
}
return 0;
}
#2028:最小公倍数,GCD+LCM
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2028
解题报告:http://blog.csdn.net/qinlumoyan/article/details/38661177
#2029:回文串判断
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2029
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 100+10;
int t,tmp;
char str[MAXN];
int main(){
scanf("%d",&t);
while(t--){
cin>>str;tmp=1;
int len=strlen(str);
for(int i=0;i<=len/2;i++){
if(str[i]!=str[len-1-i]){
tmp=0;break;
}
}
if(tmp) cout<<"yes"<<endl;
else cout<<"no"<<endl;
}
return 0;
}
#2030:统计汉字的个数: 一个汉字在字符串中是以两个负的字符形式存储,因此统计结果除以2
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2030
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 10000;
char str[MAXN];
int n,sum;
int main(){
scanf("%d",&n);
getchar();
while(n--){
gets(str);
sum=0;
int len=strlen(str);
for(int i=0;i<len;i++){
if(str[i]<0) sum++;
}
cout<<sum/2<<endl;
}
return 0;
}
#2031:进制转换:考虑负数和大于10的进制转换
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2031
#include <iostream>
#include <cstdio>
#include <stack>
using namespace std;
int n,r,num,flag;
int main(){
stack<int> s;
while(scanf("%d%d",&n,&r)!=EOF){
while(!s.empty()) s.pop();
flag=0;
if(n<0){n=-n;flag=1;}
while(n){
s.push(n%r);
n/=r;
}
if(flag) printf("-");
while(!s.empty()){
num=s.top();
if(r>10 && num>=10)
printf("%c",num-10+'A');
else printf("%d",num);
s.pop();
}
printf("\n");
}
return 0;
}
#2032:杨辉三角
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2032
解题报告: http://blog.csdn.net/qinlumoyan/article/details/38678243#2033:计算时分秒的加法
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2033
#include <iostream>
#include <cstdio>
using namespace std;
int ah,am,as,bh,bm,bs,h,m,s;
int n;
int main(){
scanf("%d",&n);
while(n--){
h=m=s=0;
scanf("%d%d%d%d%d%d",&ah,&am,&as,&bh,&bm,&bs);
s=as+bs;
if(s>=60) {s-=60;m++;}
m+=am+bm;
if(m>=60) {m-=60;h++;}
h+=ah+bh;
printf("%d %d %d\n",h,m,s);
}
return 0;
}
#2034:集合减法
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2034
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
using namespace std;
const int MAXN = 100+10;
int n,m,numa,numb,flag;
int a[MAXN],b[MAXN];
int ans[MAXN];
int main(){
priority_queue<int,vector<int>,greater<int> > q;
while(scanf("%d%d",&n,&m)!=EOF && (n||m)){
flag=0;
memset(ans,0,sizeof(ans));
for(int i=0;i<n;i++){
scanf("%d",&numa);
ans[numa]=1;
}
for(int i=0;i<m;i++){
scanf("%d",&numb);
ans[numb]=0;
}
for(int i=0;i<MAXN;i++)
if(ans[i]==1){
q.push(i);
flag=1;
}
while(!q.empty()){
printf("%d ",q.top());//每个元素都跟空格,坑呀
q.pop();
}
printf(flag==0 ? "NULL\n" : "\n");
}
return 0;
}
#2035:求平方的最后三位数
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2035
#include <iostream>
#include <cstdio>
using namespace std;
int a,b,ans;
int main(){
while(scanf("%d%d",&a,&b)!=EOF && (a||b)){
ans=1;
for(int i=0;i<b;i++){
ans*=a;
if(ans>1000) ans%=1000;
}
printf("%d\n",ans);
}
return 0;
}
#2036:计算几何:求多边形面积
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2036
解题报告:http://blog.csdn.net/qinlumoyan/article/details/38686541
#2037:今年暑假不AC:贪心
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2037
解题报告:http://blog.csdn.net/qinlumoyan/article/details/38688759
#2038:木有这个题,呵呵呵
#2039:三角形:有一个小坑
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2039
#include <iostream>
#include <cstdio>
using namespace std;
int n;
double a,b,c; //是正数,没说不是小数呀,这个题雷到我了,好多人栽倒上面了,注意类型,汗...
int main(){
scanf("%d",&n);
while(n--){
scanf("%lf%lf%lf",&a,&b,&c);
if(a+b>c && a+c>b && c+b>a) printf("YES\n");
else printf("NO\n");
}
return 0;
}
#2040:亲和数
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2040
#include <iostream>
#include <cstdio>
using namespace std;
int m,a,b,suma,sumb;
int main(){
scanf("%d",&m);
while(m--){
suma=1;sumb=1;
scanf("%d%d",&a,&b);
for(int i=2;i<a;i++)
if(a%i==0) suma+=i;
for(int i=2;i<b;i++)
if(b%i==0) sumb+=i;
if(suma==b && a==sumb) printf("YES\n");
else printf("NO\n");
}
return 0;
}
#2041:典型的Fibonacci数列问题
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2041
解题报告: http://blog.csdn.net/qinlumoyan/article/details/38687933#2042:不容易系列之二:找规律
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2042
#include <iostream>
#include <cstdio>
using namespace std;
int n,t,sum;
int main(){
scanf("%d",&t);
while(t--){
sum=3;
scanf("%d",&n);
for(int i=0;i<n;i++){
sum-=1;
sum*=2;
}
printf("%d\n",sum);
}
return 0;
}
#2043:密码判断:模拟
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=2043
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int MAXN = 50+5;
char pwd[MAXN];
int m,flag1,flag2,flag3,flag4,num;
int main(){
scanf("%d",&m);
while(m--){
scanf("%s",pwd);
int len=strlen(pwd);
if(len<8 || len>16){
printf("NO\n");
continue;
}
num=0;flag1=0;flag2=0;flag3=0;flag4=0;
for(int i=0;i<len;i++){
if(pwd[i]>='A' && pwd[i]<='Z' && flag1==0) {num++;flag1=1;}
if(pwd[i]>='a' && pwd[i]<='z' && flag2==0) {num++;flag2=1;}
if(pwd[i]>='0' && pwd[i]<='9' && flag3==0) {num++;flag3=1;}
if((pwd[i]=='~' || pwd[i]=='!' || pwd[i]=='@' ||pwd[i]=='#' ||pwd[i]=='$' || pwd[i]=='%' || pwd[i]=='^')&&flag4==0) {num++;flag4=1;}
}
if(num>=3) printf("YES\n");
else printf("NO\n");
}
return 0;
}
#2044-#2050:递推求解专题
解题报告: http://blog.csdn.net/qinlumoyan/article/details/38712107