北航2013年机试

1.题目描述: 

给一个真分数的分子分母,输出约分后的分子分母

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define inf 99999
int gcd(int a,int b){
	if(b==0)return a;
	else return gcd(b,a%b);
}
int main(){
    int a,b;
	scanf("%d%d",&a,&b);
    if(a==0)printf("0 %d\n",b);
    else {
		int t=gcd(a,b);
		printf("%d %d\n",a/t,b/t);
	}
	return 0;
}

2.北航2013年机试

#include<stdio.h>
#include<string.h>
int main(){
    char str[10];
	int a[10][10],i,j,k;
	memset(a,0,sizeof(a));
	scanf("%s",str);
	for(i=0;i<strlen(str);i++){//i是行
		if(str[i]!='*'){
			int lie=str[i]-'1';
			for(j=0;j<8;j++){
				a[i][j]=1;
				a[j][lie]=1;
			}
		}
	}
	int tol=0,col;
	for(i=0;i<8;i++)
		for(j=0;j<8;j++){
            if(a[i][j]==0)col=j+1,tol++;
		}
	if(tol==1)printf("%d\n",col);
	else printf("NO ANSWER\n");
	return 0;
}
//5  15
/*
1 1 1 1 1 1 1 1 
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 0
1 1 1 1 1 0 1 1
*/

3.给出一个标准输入的正数(开头末尾没有多余的0),输出其科学计数法表示结果。比如:输入0.000002,输出2e-6;输入123.456,输出1.23456e2;输入123456,输出1.23456e2

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define inf 99999
int main(){
	char st[100];
	int i,j,len,k=0; 
	scanf("%s",st);
	len=strlen(st);
	for(i=0;i<len;i++){
       if(st[i]=='.')
           k=i;
	}
	if(k==0){
		printf("%c.",st[0]);
		for(i=1;i<len;i++)printf("%c",st[i]);
		printf("e%d\n",len-1);
	}
	else {
	if(st[0]=='0'){
		 i=2;
         while(st[i]=='0'){
			 i++;
		 }
		 if(i==len-1){
			 printf("%ce-%d\n",st[i],i-1);
		 }
		 else {
			 printf("%c.",st[i]);
			 for(j=i+1;j<len;j++)printf("%c",st[j]);
			 printf("e-%d\n",i-1);
		 }
	}
	else {
		printf("%c.",st[0]);
		for(i=1;i<len;i++){
			if(st[i]=='.')continue;
			printf("%c",st[i]);
		}
		printf("e%d\n",k-1);
	}
	}
	return 0;
}