hdu1019

这题因为没看清题意,WA了7次

抓狂妈的太恶心了!

下面每行测试实例中,第一个数字竟然是后面数字的个数! 之前一直把它也算进去,结果无限WA啊 大哭

亏得还想各种办法弄“不指定个数的输入”问题,即用getchar()看是否到\n了,又用sstream串流类的

还是WA, 晕死

不过还能收获个新用法,从数组中读数据,这玩意儿相当高档啊

#include<iostream>
#include<string>
#include<sstream> //串流类对象

int main()
{
	freopen("E:\\in.txt","r",stdin);
	int n;
	string line;
	cin >> n;
	getline(cin,line); 		//clear '\n'
	while(n--)
	{
		getline(cin,line);
		istringstream iss(line);
		
		__int64 a,xresult = 1;
		while(iss >> a)
		{			
			xresult = lcm(xresult,a);		
		}
		cout << xresult << endl;
	}
	return 0;
}

把代码贴出来吧,血和泪啊。。

//Problem:hdu1019
//Data:2011/10/30

#include <iostream>
#include <string>
#include <sstream>
using namespace std;

__int64 gcd(__int64 a, __int64 b)
{
    int temp;
    if(a < b)
    {
        temp = a;
        a = b;
        b = temp;
    }

    while(b != 0)
    {
        temp = a%b;
        a = b;
        b = temp;
    }
    return a;
}

__int64 lcm(__int64 a, __int64 b)
{
	__int64 temp;
	if(a < b)
    {
        temp = a;
        a = b;
        b = temp;
    }
    return a/gcd(a,b) * b ;
}

int main()
{
	//freopen("E:\\in.txt","r",stdin);
	int n;
	cin >> n;
	while(n--)
	{	
		int t;
		__int64 a,result = 1;
		cin >> t;
		while(t--)
		{
			cin >> a;
			result = lcm(result,a);	
		}	
		cout << result << endl;
	}
	return 0;
}


/*
int main()
{
	freopen("E:\\in.txt","r",stdin);
	int n;
	cin >> n;
	while(n--)
	{
		__int64 a,result = 1;
		while(true)
		{
			cin >> a;
			result = lcm(result,a);
			char c = getchar();
			if(c == '\n' || c == EOF)
			{
				cout << result << endl;
				break;
			}
		}	
	}
	return 0;
}
*/

/*
//火大!!!竟然看错题了,原来第一个数字是后面的字数量!!!!!! Shit 
int main()
{
	freopen("E:\\in.txt","r",stdin);
	int n;
	string line;
	cin >> n;
	getline(cin,line); 		//clear '\n'
	while(n--)
	{
		getline(cin,line);
		istringstream iss(line);
		
		__int64 a,xresult = 1;
		while(iss >> a)
		{			
			xresult = lcm(xresult,a);		
		}
		cout << xresult << endl;
	}
	return 0;
}
*/


Fuck 英文题!!!!

壮哉我大中华民族!

壮哉汉语!

早晚有一天,考中文托福,考死你们这群老外!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值