ACM 实验室2020.10.10天梯赛练习*2

7-1 估值一亿的AI核心代码 (20分)

题意:略
/*
csdn:
    https://blog.csdn.net/dengkuomin/article/details/89053402
*/


#include <bits/stdc++.h>
using namespace std;
int main()
{
	int sum;
	cin>>sum;
	getchar();
	string a[sum];
	for(int i=0;i<sum;i++)
		getline(cin,a[i]);
	
	for(int i=0;i<sum;i++){
		string temp=a[i];
		cout<<temp<<endl<<"AI:";
		for(int j=0;j<temp.length();j++){
			if(isalnum(temp[j])){	//isalnum()判断是不是字母或者数字 
				if(temp[j]!='I')
					temp[j]=tolower(temp[j]); 	//tolower()变成小写字母 
			}
			else{
				temp.insert(j," ");
				j++;
			} 
			if(temp[j]=='?')
				temp[j]='!';
		}
		
		string str[1001],tmp;
		int flag=0;
		stringstream ss(temp);	//空格来存放分开的字符串 
		while(ss>>tmp)
			str[flag++]=tmp;
		
		if(!isalnum(str[0][0]))	//如果第一个是其他字符,也需要空一格 
			cout<<" ";
		
		for(int i=0;i<flag;i++){
			if(!isalnum(str[i][0]))	//标点符号前不能有空格 
				cout<<str[i];
			else if(str[i]=="can" && str[i+1]=="you"){
				cout<<" I can";
				i++;
			}
			else if(str[i]=="could" && str[i+1]=="you"){
				cout<<" I could";
				i++;
			}
			else if(str[i]=="I" || str[i]=="me")
				cout<<" you";
			else
				cout<<" "<<str[i];
		}
		cout<<endl;
	}
	return 0;
} 

7-2 是不是太胖了 (5分)

题意:略
#include <iostream>
using namespace std;

int main()
{
    double f;
    cin >> f;
    
    printf("%.1lf\n",(f - 100) * 1.8);
    
    return 0;
}

7-3 N个数求和 (20分)

题意:略
#include <iostream>
#include <algorithm>
using namespace std;

int x,y;

int main()
{
    int n;
    cin >> n;
    int a,b;
    scanf("%d/%d",&a,&b);
    x = a,y = b;
    n --;
    while(n --)
    {
        int a,b;
        scanf("%d/%d",&a,&b);

        int a1 = b * x + a * y;
        x = a1;
        y = b * y;
        
        if(x < 0){
            x = -x;
            int t = __gcd(x,y);
            x = x / t;
            y = y / t;
            x = -x;
        }
        else{
            int t = __gcd(x,y);
            x = x / t;
            y = y / t;
        }
    }
    
    if(y == 1){
        cout << x << endl;
    }else{
        if(x / y){
            cout << x / y << ' ' << x - y * (x / y) << '/' << y << endl;    
        }
        else{
            cout << x - y * (x / y) << '/' << y << endl;
        }
    }
    
    return 0;
}

7-4 求整数段和

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值