ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

杭电oj2039 1062 1064 1989 2734 1197

2020-03-07 13:04:12  阅读:221  来源: 互联网

标签:2734 main oj2039 int 1062 cin will using include


2039 判断三边是否可以构成三角形
这道题刚开始用int定义了变量是wrong,double定义后就AC了,看来题目中没说是整数变量的都要谨慎一点

#include<iostream>
using namespace std;
int main(){
	int M;
	double a,b,c;
	cin>>M;
	while(M--){
		cin>>a>>b>>c;
		if((a+b>c)&&(a+c>b)&&(c+b>a))
		 cout<<"YES"<<endl;
		else
		 cout<<"NO"<<endl;			
	} 
	return 0; 
} 

1062字符串中 单词的翻转
注意要吸收回车,因为输入数字T的时候按下回车后,输入缓冲区还残留着回车,而getline,gets都是接收回车的,用来接收回车可以用get getchar ignore

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
    int T;
    char a[1000];
    char p;//用于交换的中间变量
    cin>>T;
 //cin.ignore(1,'\n');
   getchar();
 //cin.get();
 while(T--){
  int i=-1;
cin.getline(a,1000);
  for(int n=0;n<=strlen(a);n++){
   i++;
   if(a[n]==' '||a[n]=='\0'){
    int l=i/2;/*交换的次数为该字母的长度的二分之一*/ 
    int f=n-i;/*需要交换的字母的第一个字符的位置*/
    int j=n-1;/*需要交换的字母的最后一个位置*/
    while(l--){/*开始交换*/
     p=a[f];
     a[f]=a[j];
     a[j]=p;
     f++;
     j--;

    }
     i=-1;/*i变量开始重新计数*/
   }//if
   
   }//for
  for(int i=0;i<=strlen(a);i++){
   cout<<a[i];
  }//循环输出数组
  cout<<endl; //每输出一个样例换行

  }//样例个数循环
  return 0;
 }

法二用了c++的翻转函数

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
    char s[1000];
	char *c;
	int T;
	cin>>T;
	cin.ignore(1,'\n');
	while(T--){
	   cin.getline(s,1000);
	   c=&s[0];
	   for(int n=0;n<=strlen(s);n++){
	   	if(s[n]==' '||s[n]=='\0'){
		   reverse(c,&s[n]);
		   c=&s[n+1];//开始位置下移
		    
		   }
	   	}
	   	cout<<s<<endl;
	   }
	
	}
 

1064 经济管理
The input will be twelve lines. Each line will contain the closing balance of his bank account for a particular month. Each number will be positive and displayed to the penny. No dollar sign will be included.

The output will be a single number, the average (mean) of the closing balances for the twelve months. It will be rounded to the nearest penny, preceded immediately by a dollar sign, and followed by the end-of-line. There will be no other spaces or characters in the output.

100.00
489.12
12454.12
1234.10
823.05
109.20
5.27
1542.25
839.18
83.99
1295.01
1.75

Sample Output

$1581.42

#include<iostream>
using namespace std;
int main(){
	int M,a,b,c,t;
	cin>>M;
	while(M--){
		cin>>a>>b>>c;
		if((a+b>c)&&(a+c>b)&&(c+b>a))
		 cout<<"YES"<<endl;
		else
		 cout<<"NO"<<endl;			
	} 
	return 0; 
} 

2734
问题描述:So, A=1, B=2, etc., through Z=26. Here are example Quicksum calculations for the packets “ACM” and “MID CENTRAL”:
ACM: 11 + 23 + 313 = 46MID CENTRAL: 113 + 29 + 34 + 40 + 53 + 65 + 714 + 820 + 918 + 101 + 1112 = 650
即字符串中字母的位置乘字母在26个字母表的位置然后相加,输入的必须是大写字母,以字母开始,以字母结束,字符串的空格在字母表中代表0位置
思路:要用数组,下标代表位置。对于字母表的位置,A-Z ACSLL为65-90,可以用ACSLL码减64得出位置。循环找出空格的位置,和字母区别对待。

#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main(){
	char arr[260];
	while(1){
  	cin.getline(arr,260);
		if(arr[0]=='#')
		   break;
		   int sum=0;
		 int length=strlen(arr);
		 for(int i=0;i<length;i++){
		 	if(arr[i]!=' ')
		 	   sum+=(arr[i]-64)*(i+1);
		 } 
		 cout<<sum<<endl; 
	} 
	return 0; 
} 

1197
题目大意:找到所有的四位数字,这个四位数字十进制表示的各位的和等于十六进制表示的各位和等于十二进制表示的各位的和
找到并列出来

#include <iostream>
using namespace std;
int main()
{   
    for(int i=2992;i<10000;i++){
    	int a=0,b=0,c=0,r=0,n=0;
        int j=i;
        a=i/1000+i/10%10+i/100%10+i%10;//十进制各位的和
	//用除基取余法将十进制转换成十六进制,十二进制 
        while(j!=0){
            r=j%16;
            b+=r;//余数的和为b 
            j=j/16;
        }
        j=i;
        while(j!=0){
            n=j%12;
            c+=n;
            j=j/12;
        }
        if(a==b&&b==c){
        	 cout<<i<<endl;
        }
    }

    return 0;
}


标签:2734,main,oj2039,int,1062,cin,will,using,include
来源: https://blog.csdn.net/weixin_45191675/article/details/104710469

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有