1 条题解
-
0
C :
#include "math.h" int main(int argc, char* argv[]) { int n,a,b,c; char str[2],str1[2]; scanf("%d",&n); while(n--) { scanf("%s%d%s%d",str,&a,str1,&b); if(str[0]=='A') { if(str1[0]=='B') { c=sqrt((a*a+b*b)); printf("A %d B %d C %d\n",a,b,c); } else { c=sqrt((b*b-a*a)); printf("A %d B %d C %d\n",a,c,b); } } if(str[0]=='B') { if(str1[0]=='A') { c=sqrt((a*a+b*b)); printf("A %d B %d C %d\n",b,a,c); } else { c=sqrt((b*b-a*a)); printf("A %d B %d C %d\n",c,a,b); } } if(str[0]=='C') { if(str1[0]=='A') { c=sqrt((a*a-b*b)); printf("A %d B %d C %d\n",b,c,a); } else { c=sqrt((a*a-b*b)); printf("A %d B %d C %d\n",c,b,a); } } } return 0; }
C++ :
#include <iostream> #include <math.h> #include <stdio.h> using namespace std; int main() { int T,n,m; char a,b,c; cin>>T; while(T--) { int x,y; cin>>a>>n>>b>>m; if(a=='C') { x=sqrt(n*n-m*m); if(b=='A') printf("A %d B %d C %d\n",m,x,n); else printf("A %d B %d C %d\n",x,m,n); } else if(b=='C') { x=sqrt(m*m-n*n); if(a=='A') cout<<a<<" "<<n<<" "<<"B "<<x<<" "<<b<<" "<<m<<endl; else printf("A %d B %d C %d\n",x,n,m); } else { x=sqrt(n*n+m*m); cout<<a<<" "<<n<<" "<<b<<" "<<m<<" "<<"C "<<x<<endl; } } return 0; }
Java :
import java.util.Scanner; public class Main { public static void main(String[] args) { int N; Scanner s = new Scanner(System.in); N = s.nextInt(); while(s.hasNext()&&N>0){ int a = 0,b = 0,c = 0; String[] str = new String[4]; for (int i = 0; i <4; i++) { str[i] = s.next(); } for (int i = 0; i < str.length; i+=2) { if(str[i].equals("A")){ a=Integer.parseInt(str[i+1]); } if(str[i].equals("B")){ b=Integer.parseInt(str[i+1]); } if(str[i].equals("C")){ c=Integer.parseInt(str[i+1]); } } if(a==0){ a=(int) Math.sqrt(c*c-b*b); } if(b==0){ b=(int) Math.sqrt(c*c-a*a); } if(c==0){ c=(int) Math.sqrt(a*a+b*b); } System.out.println("A "+a+" "+"B "+b+" "+"C "+c); N--; } } }
- 1
信息
- ID
- 3167
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- (无)
- 标签
- 递交数
- 0
- 已通过
- 0
- 上传者