nyoj 可以直接写的简单题

Triangular Sums nyoj 122


#include<iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    for(int count=1;count<=N;count++)
    {
            int m, num=0;
            cin>>m;
            for(int i=1;i<=m;i++)
                    num += i*((i+1)*(i+2)/2);
            cout<<count<<" "<<m<<" "<<num<<endl;
    }
    return 0;
}

爱摘苹果的小明 nyoj 50

#include<iostream>

using namespace std;
int main()
{
    int N;
    int a[10];
    cin>>N;
    while(N--)
    {
              for(int i=0;i<10;i++)
                      cin>>a[i];
              int m, count=0;
              cin>>m;
              for(int i=0;i<10;i++)
                    if(a[i] <= (m+30))
                            count++;
              cout<<count<<endl;
    }
    return 0;
}

国王的魔镜 nyoi 264

我用到了字符串的逆序

#include<iostream>
#include<string>
using namespace std;
int main()
{
    int N;
    string str;
    cin>>N;
    while(N--)
    {
              cin>>str;
              if((str.size() % 2) == 1)
              {
                             cout<<str.size()<<endl;
                             continue;
              }
              else
              {
                  string s(str);
                  while(str.size()%2 == 0 && str == s)
                  {
                                     s = str.substr(str.size()/2, str.size()/2);
                                     string s1(s.rbegin(),s.rend());
                                     s = s1;
                                     str = str.substr(0, str.size()/2);
                                       
                                     
                  }
                  if(str.size() %2 == 1  && str == s)
                         cout<<str.size()<<endl;
                  else
                      cout<<str.size()+s.size()<<endl;
              }
    }
    return 0;
}


字符串逆序输出 nyoj 266

把两个串合并成一个,然后逆序

#include<iostream>
#include<string>
using namespace std;
int main()
{
    string str;
    string str2;
    int N;
    cin>>N;
    while(N--)
    {
           cin>>str>>str2;
           str += str2;
           string s(str.rbegin(), str.rend());
           for(int i=0;i<s.length();i++)
           {
                   if(s.at(i) >= 'a' && s.at(i) <= 'z')
                              cout<<s.at(i);
           }  
           cout<<endl; 
    }
    return 0;
}


不高兴的小明 nyoj 53

#include<iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
              int max=0, a, b, index;
              for(int i=1;i<=7;i++)
              {
                      cin>>a>>b;
                      if(a + b   >   max)
                      {
                           max = a+b;
                           index = i;
                      }
              }
              if(max <=8)
                     cout<<0<<endl;
              else
                     cout<<index<<endl;
    }
    return 0;
}

分数拆分 nyoj 66

直接写

#include<iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
              int m;
              cin>>m;
              for(int i=m+1;i<=2*m;i++)
              {
                      if((i* m  %  (m-i)) == 0)
                             cout<<"1/"<<m<<"=1/"<<(i*m)/(i-m)<<"+1/"<<i<<endl;
              }
    }
    return 0;
}

另类乘法 nyoj 121
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
              int a, b, m, temp;
              cin>>a>>b;
              double sum = 0;
              while(a)
              {
                   m = a % 10;
                   a = a / 10;
                   temp = b;
                   while(temp)
                   {
                              sum += m * (temp%10);
                              temp /= 10;
                   }   
              }
              cout<<sum<<endl;
    }
    return 0;
}
此题最优程序
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
              string s1, s2;
              cin>>s1>>s2;
              int sum =0;
              for(int i=0;i<s1.size();i++)
                      for(int j=0;j<s2.size();j++)
                              sum += (s1.at(i)-'0')*(s2.at(j)-'0');
              cout<<sum<<endl;
    }
    return 0;
}



盗梦空间 nyoj 125
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
              string str;
              int m, second=0, div=1;
              cin>>m;
              while(m--)
              {
                        cin>>str;
                        if(str == "IN")
                               div *= 20;
                        else if(str == "STAY")
                        {
                             int stay;
                             cin>>stay;
                             second += (stay * 60) / div;
                        }
                        else
                            div /= 20;
              }
              cout<<second<<endl;
    }
    return 0;
}

小明求素数积 nyoj 225
#include<iostream>
using namespace std;
int prime[]={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401,409,419,421,431,433,439,443,449,457,461,463,467,479,487,491,499,503,509,521,523,541,547,557,563,569,571,577,587,593,599,601,607,613,617,619,631,641,643,647,653,659,661,673,677,683,691,701,709,719,727,733,739,743,751,757,761,769,773,787,797,809,811,821,823,827,829,839,853,857,859,863,877,881,883,887,907,911,919,929,937,941,947,953,967,971,977,983,991,997,1009};
int main()
{
    int N, m, num;
    cin>>N;
    while(N--)
    {
          cin>>m;
          num = 1;
          for(int i=0;prime[i]<=m;i++)
          {
                  num *= prime[i];
                  num %= 1000000;
          }
          cout<<num<<endl;    
    }
    return 0;
}

玩转矩阵的C小加 nyoj 261
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
              int a[3][3];
              cin>>a[0][0]>>a[0][1]>>a[0][2]>>a[1][0]>>a[1][1]>>a[1][2]>>a[2][0]>>a[2][1]>>a[2][2];
              cout<<a[0][0]<<" "<<a[1][0]<<" "<<a[2][0]<<endl<<a[0][1]<<" "<<a[1][1]<<" "<<a[2][1]<<endl<<a[0][2]<<" "<<a[1][2]<<" "<<a[2][2]<<endl;              
    } 
    return 0;   
}
正三角形外接圆面积 nyoj 274
#include <iostream>
using namespace std;
#define PI 3.1415926
int main()
{
	int m;
	cin>>m;
	while(m--)
	{
		double s,a;
		cin>>a;
		s=PI*a*a/3.0;
		cout.setf(ios_base::fixed);
		cout.precision(2);
		cout<<s<<endl;
	}
	return 0;
} 

算菜价 nyoj 316
#include<stdio.h>
int main()
{
	double a,b,sum=0;
	char c[20];
	while(scanf("%s%lf%lf",c,&a,&b)!=EOF)
	{
		sum=sum+a*b;
	}
	printf("%.1lf\n",sum);
	return 0;
}   

猴子吃桃 nyoj 324
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin>>N;
    while(N--)
    {
              int m;
              cin>>m;
              int num=1;
              for(int i=0;i<m;i++)
              {
                      num = (num+1) * 2;
              }
              cout<<num<<endl;
    }
    return 0;
}

整除个数 nyoj 399
#include<iostream>
using namespace std;
int main()
{
    int n, b;
    while(cin>>n>>b)
          cout<<n/b<<endl;
    return 0;
}

黑色帽子 nyoj 455
#include<iostream>
using namespace std;
int main()
{
    unsigned int N, m;
    cin>>N;
    while(N--)
    {
              cin>>m;
              cout<<m<<endl;
    }
    return 0;
}

九九乘法表 nyoi 463
#include<iostream>
using namespace std;
int main()
{
    int N,M;
    cin>>N;
    while(N--)
    {
              cin>>M;
              for(int i=1;i<=M;i++)
              {
                      cout<<i<<"*"<<i<<"="<<i*i;
                      for(int j=i+1;j<=9;j++)
                              cout<<" "<<i<<"*"<<j<<"="<<i*j;
                      cout<<endl;
              }
    }
    return 0;
}

A+B problem III
#include<iostream>
using namespace std;
int main()
{
    int N;
    double a , b, c;
    cin>>N;
    while(N--)
    {
              cin>>a>>b>>c;
              if(((a+b)-c) < 0.0001  && ((a+b)-c) > -0.0001)
                           cout<<"Yes"<<endl;
              else
                  cout<<"No"<<endl;
    }        
    return 0;
}

日期计算 nyoj 75
#include<iostream>
using namespace std;


bool isLeap(int year)
{
      if(((year%4 == 0) && (year%100 != 0)) || year%400 == 0)
                  return true;
      return false;
}
int main()
{
    int a[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
    int N;
    cin>>N;
    int year, month, day;
    while(N--)
    {
         int num = 0;
         cin>>year>>month>>day;
         for(int i=1;i<month;i++)
         {
                 num += a[i];
         }
         num += day;
         if(isLeap(year) && (month >= 3)) 
                         num++;
         cout<<num<<endl;    
    }
    return 0;
}

成绩转换 nyoj 98
#include<iostream>
using namespace std;
int main()
{
    int N, score;
    cin>>N;
    while(N--)
    {
              cin>>score;
              if(score >= 90  &&  score <= 100)
                       cout<<"A"<<endl;
              else if(score >= 80  &&  score <= 89)
                       cout<<"B"<<endl; 
              else if(score >= 70  &&  score <= 79)
                       cout<<"C"<<endl;
              else if(score >= 60  &&  score <= 69)
                       cout<<"D"<<endl;
              else if(score >= 0  &&  score <= 59)
                       cout<<"E"<<endl;                     
    }
    return 0;
}


你可能感兴趣的:(简单)