1101 B是A的多少倍 (15 分) PTA乙级

#include<iostream>
#include <queue>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include <iomanip> 
#include <algorithm>
#pragma warning(disable:4996)
using namespace std;
int stringtoint(string a)
{
	int count = 1;
	int res=0;
	int sum = a.size();
	for (;sum > 0;sum--)
	{
		res += (a[sum - 1]-'0') * count;
		count *= 10;
	}
	return res;
}//string转int
int main()
{
	string a;
	int n;
	cin >> a>>n;
	int s = a.size();
	//cout << s << endl;
	string b="";
	for (int i=0;i<n;i++)
	{
		b = b + a[i+s-n];
	}
	for (int i = 0;i < s - n;i++)
	{
		b = b + a[i];
	}
	double a_i = double(stringtoint(a));
	double b_i = double(stringtoint(b));
	//cout << a_i << " " << b_i << endl;
	printf("%.2f", b_i / a_i);

}
上一篇:DNA sequence HDU - 1560(IDA*)


下一篇:畅通工程(最小生成树and并查集算法)HDU - 1232