赞
踩
- #include<iostream>
- using namespace std;
- int f[20]; //f[i]第i只猫拿走鱼之前的待分配鱼数
- int main(){
- int n,a;
- cin>>n>>a;
- //枚举最后一只猫拿走的鱼数
- for(int i=1;;i++){
- int flag=1;//n只小猫都成功分到了鱼
- f[n]=i*n+a; //第n只猫待分配的鱼数
- //从倒数第2只到第一只
- for(int j=n;j>=2;j--){
- if(f[j]%(n-1)==0){//如果符合条件
- f[j-1]=f[j]/(n-1)*n+a;
- }else{
- flag=0;
- break;
- }
- }
- if(flag==1){
- cout<<f[1];
- return 0;
- }
- }
- return 0;
- }
- #include <bits/stdc++.h>
- using namespace std;
- int main() {
- int n;
- long long k, ans;
- string a, b;
- char c;
- cin >> n;
- for(int i = 1; i <= n; i++) {
- cin >> k >> a >> c >> c >> b;
- if (a == "g") {
- if (b == "kg") {
- ans = k / 1000;
- } else if(b == "mg") {
- ans = k * 1000;
- } else {
- ans = k;
- }
- } else if(a == "kg") {
- if (b == "g") {
- ans = k * 1000;
- } else if(b == "mg") {
- ans = k * 1000000;
- } else {
- ans = k;
- }
- } else if(a == "mg") {
- if (b == "g") {
- ans = k / 1000;
- } else if(b == "kg") {
- ans = k / 1000000;
- } else {
- ans = k;
- }
- } else if (a == "m") {
- if (b == "km") {
- ans = k / 1000;
- } else if(b == "mm") {
- ans = k * 1000;
- } else {
- ans = k;
- }
- } else if(a == "km") {
- if (b == "m") {
- ans = k * 1000;
- } else if(b == "mm") {
- ans = k * 1000000;
- } else {
- ans = k;
- }
- } else if(a == "mm") {
- if (b == "m") {
- ans = k / 1000;
- } else if(b == "km") {
- ans = k / 1000000;
- } else {
- ans = k;
- }
- }
- cout << k << " " << a << " = " << ans << " " << b << endl;
- }
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。