分享到新浪微博 分享到QQ空间 打印

[灌水] NOIP2008提高组复赛试题

CPP的数组真烦……只能数字做下标……
先给出第一个
复制内容到剪贴板
代码:

#include <iostream>
#include <math.h>
using namespace std;
void sunum(int n){
int k;
for(k=2;k<n;k++){
  if(n%k==0){
    break;
  }
}
  if(k>=n&&(n!=0&&n!=1)){
    cout<<"Lucky Word"<<endl;
    cout<<n<<endl;
  }else{
    cout<<"No Answer"<<endl;
    cout<<0<<endl;
  }
}
int main (int argc, char *argv[])
{
  char word[100];
  int num,i,n;
  static int stat[25];
  cout<<"word.in"<<endl;
  cin.getline(word,100);
  char *wordin=word;
  i=0;
  n=strlen(wordin);
  while(i<n){
    switch(word[i]){
      case 'a':stat[0]+=1;break;
      case 'b':stat[1]+=1;break;
      case 'c':stat[2]++;break;
      case 'd':stat[3]++;break;
      case 'e':stat[4]++;break;
      case 'f':stat[5]++;break;
      case 'g':stat[6]++;break;
      case 'h':stat[7]++;break;
      case 'i':stat[8]++;break;
      case 'j':stat[9]++;break;
      case 'k':stat[10]++;break;
      case 'l':stat[11]++;break;
      case 'm':stat[12]++;break;
      case 'n':stat[13]++;break;
      case 'o':stat[14]++;break;
      case 'p':stat[15]++;break;
      case 'q':stat[16]++;break;
      case 'r':stat[17]++;break;
      case 's':stat[18]++;break;
      case 't':stat[19]++;break;
      case 'u':stat[20]++;break;
      case 'v':stat[21]++;break;
      case 'w':stat[22]++;break;
      case 'x':stat[23]++;break;
      case 'y':stat[24]++;break;
      case 'z':stat[25]++;break;
    }
    i++;
  }
  i=0;
  int max=0,min=100;
  while(i<26){
    if(stat[i]!=0&&stat[i]>max) max=stat[i];
    if(stat[i]!=0&&stat[i]<min) min=stat[i];
    i++;
  }
  system("cls");
  cout<<"word.out"<<endl;
  sunum(max-min);
  
  system("pause");
  return 0;
}

TOP

果然第二题只能穷举……我已经想了一个
先穷举1000之内的所偶排列,然后从排列中按需筛选……下周有空就写上
应该不难
第三题略略看了眼……找了点可用规律,总觉得这问题眼熟……W一说是动态规划就更眼熟了
下周一并试试……

TOP

初学,很多函数不详

TOP

悲啊。资料太少,练习太少,学习时间也少……慢慢来得了

TOP