栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

zoj 1225 Scramble Sort

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zoj 1225 Scramble Sort

#include<iostream>#include<algorithm>#include<stdio.h>#include<string.h>using namespace std;char line[2000], buff[500];struct chrs{ char chr[100];} achrs[100];int num, s, e, intp, chrp;int ints[500];bool ioc[1000];bool operator<( const chrs& a, const chrs& b ){ char ta, tb; for( int i=0; ; i++ ) {  ta=a.chr[i];  tb=b.chr[i];  if( ta>='a')   ta-=32;  if( tb>='a' )   tb-=32;  if( ta<tb )   return 1;  else if( ta>tb )   return 0; }}int main(){ while( cin.getline (line , 255 , 'n') ) {  if(line[0]=='.')   break;  num = s= intp = chrp = 0;  for( num=0; ; num++ )  {   for( e=s; line[e]!=',' && line[e]!='.' ; e++ )    buff[e-s]=line[e];   buff[e-s]=0;   if( line[e]==',' )    s=e+2;   if( buff[0]=='-' || ( buff[0]>='0' && buff[0]<='9' ) )   {    ints[intp++]=atoi( buff );    ioc[num]=1;   }   else   {    strcpy( achrs[chrp++].chr, buff );    ioc[num]=0;   }   if( line[e]=='.' )    break;  }  sort(ints, ints+intp);  sort( achrs, achrs+chrp);  intp=chrp=0;  for( int i=0; i<num; i++ )  {   if( ioc[i] )    cout << ints[intp++];   else    cout << achrs[chrp++].chr;   cout  << ", ";  }  if( ioc[num] )   cout << ints[intp++];  else   cout << achrs[chrp++].chr;  cout  << "." << endl; } return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/380027.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号