| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1993 人关注过本帖
标题:OJ1002我哪里错了?
只看楼主 加入收藏
fben
Rank: 1
等 级:新手上路
帖 子:23
专家分:0
注 册:2007-8-23
收藏
 问题点数:0 回复次数:21 
OJ1002我哪里错了?
#include <cstdlib>
#include <iostream>
#include <list>
#define MAX 8
using namespace std;
/*
A, B, and C map to 2
D, E, and F map to 3
G, H, and I map to 4
J, K, and L map to 5
M, N, and O map to 6
P, R, and S map to 7
T, U, and V map to 8
W, X, and Y map to 9
*/
char chartoint(char c)
{
switch( c ) {
case 'A':
case 'B':
case 'C':
return '2';
break;
case 'D':
case 'E':
case 'F':
return '3';
break;
case 'H':
case 'I':
case 'G':
return '4';
break;
case 'J':
case 'K':
case 'L':
return '5';
break;
case 'M':
case 'N':
case 'O':
return '6';
break;
case 'P':
case 'R':
case 'S':
return '7';
break;
case 'T':
case 'U':
case 'V':
return '8';
break;
case 'W':
case 'X':
case 'Y':
return '9';
break;
default:
return 0;
break;
}


}

//if( isalnum(in) ) printf("isalnum %c\n",in); // 0 a z A Z
//if( isalpha(in) ) printf("isalpha %c\n",in); // a z A Z
//if( iscntrl(in) ) printf("iscntrl %c\n",in); //
//if( isdigit(in) ) printf("isdigit %c\n",in); // 0
//if( isgraph(in) ) printf("isgraph %c\n",in); // - 0 a z A Z
//if( islower(in) ) printf("islower %c\n",in); // a z
//if( isspace(in) ) printf("isspace %c\n",in); //
//if( ispunct(in) ) continue; // -
//if( isupper(in) ) printf("isupper %c\n",in); // A Z
//if( isxdigit(in) ) printf("isxdigit %c\n",in); // 0 a A
void aff(int * tab,int * tac ,int t){
int i=0;
int b,c;
while(i<t) {
if((c=tac[i])>1) {
b=tab[i];
printf("%d-",b/10000);
int d=b%10000;
if(d<1000) { printf("0");if(d<100){ printf("0"); if(d<10) printf("0"); }}
printf("%d %d\n",d,c);
}
i++;
}
}

int insort(int *b,int *c,int k, int j){
int i,l,p,q;
i=0;
while(b[i]<k&&b[i++]!=0);
if(i>j) return(-1);
q=1;
while(i<=j){
l=b[i];
b[i]=k;
k=l;
p=c[i];
c[i]=q;
q=p;
i++;
}
return(0);
}

int getnum(){
char s[MAX+1];
int i=0;
char in;
while(i<MAX){
scanf("%c",&in);
if(in=='\n') break;
if( isdigit(in) ) {(s[i++])=in; continue; }
int t;
if( isupper(in) ) {if(t=chartoint(in)){ (s[i++])=t; continue;} else{ return(0);}}
if(in=='-') continue;
return(0);
}
if(i!=MAX-1){
if(i>MAX-1){ while(1){ scanf("%c",&in); if(in=='\n') return(0);} }
else{return(0);}
}


return(atoi(s));
}

int main(int argc, char *argv[])
{
char num[MAX+1];
char sin[20];
int i,j,k;
int a;
int NODOUBLE=true;
int ERROR=false;

scanf("%s",&sin);
if(!(a=atoi(sin))) exit(1);

int * b = NULL;
b=(int*) malloc(a * sizeof(int));
int * c = NULL;
c=(int*) malloc(a * sizeof(int));
for(i=0;i<a;i++) b[i]=c[i]=0;

char ifg; scanf("%c",&ifg);
int coun=a;
while(!ERROR && coun-- )
{
if(k=getnum())
for(j=0;j<a;j++){
if(b[j]==0){
b[j]=k;
c[j]=1;
insort(b,c,k,j);
break;
}
if(b[j]==k){
c[j]++;
NODOUBLE=false;
break;
}
}else{ERROR=true;}

}

if(ERROR){printf("\nSample Input : \n12\n4873279\nITS-EASY\n888-4567\n3-10-10-10\n888-GLOP\nTUT-GLOP\n967-11-11\n310-GINO\nF101010\n888-1200\n-4-8-7-3-2-7-9-\n487-3279\n");}
else
if(NODOUBLE){printf("No duplicates.\n");}
else{aff(b,c,a);}
free(b); free(c);
system("PAUSE");
return EXIT_SUCCESS;
}

http://acm.pku.edu.cn/JudgeOnline/problem?id=1002

[此贴子已经被作者于2007-8-29 17:33:13编辑过]

搜索更多相关主题的帖子: map case include MAX char 
2007-08-29 17:17
雨中飞燕
Rank: 3Rank: 3
等 级:禁止访问
威 望:8
帖 子:2200
专家分:0
注 册:2007-8-9
收藏
得分:0 
system("PAUSE");不WA才怪,至于其它错误就不清楚了,没运行,你也写得太长了



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

请大家不要用TC来学习C语言
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]
2007-08-29 17:44
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 

got ACed a few years ago. Don't know if it will AC now.

============================================================

#include <iostream>
#include <map>
#include <string>
#include <utility>

using namespace std;

map<string, int> msi;
char s2[9];
bool dup;

char table[27]="22233344455566677778889999";


void convert(const string& s)
{
int i, j=0;
string t;

for(i=0; i<s.size(); ++i)
{
if(j==3)
++j;
if( (s[i]>='A' && s[i]<='P') || (s[i]>='R' && s[i]<='Y'))
s2[j++]=table[s[i]-'A'];
else if(s[i]>='0' && s[i]<='9')
s2[j++] = s[i];
}

s2[3]='-';
s2[8]='\0';

t=s2;
if(msi.find(t)==msi.end())
msi.insert(make_pair(t, 1));
else
{
++msi[string(t)];
dup=true;
}
}

int main()
{
int n, i;
string s;
char str[1000];

while(cin>>n)
{
msi.clear();
dup=false;

for(i=1; i<=n; ++i)
{
//cin>>s;
scanf("%s", str);
s=str;
convert(s);
}

if(!dup)
cout<<"No duplicates."<<endl;
else
{
for(map<string, int>::const_iterator p=msi.begin(); p!=msi.end(); ++p)
{
if(p->second>1)
printf("%s %d\n", p->first.c_str(), p->second);
//cout<<p->first<<" "<<p->second<<endl;
}

}
}

return 0;
}


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-08-29 18:09
雨中飞燕
Rank: 3Rank: 3
等 级:禁止访问
威 望:8
帖 子:2200
专家分:0
注 册:2007-8-9
收藏
得分:0 

Name: "HJin" Problem ID "38"
Submit Time: 2007/8/30-11:13

G++: Compile Warning:
Line In function `void convert(const std::string&)':
Line 20: warning: comparison between signed and unsigned integer expressions

Test 1: Accepted Time = 0 ms
Test 2: Accepted Time = 10 ms
Test 3: Time Limit Exceed
────────────────
Problem ID 38
Test Result Time Limit Exceed
Total Time Null
Total Memory 280 Kb
Code Length 1373 Bytes

不是PKU的结果,不过是我自己加了数据



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

请大家不要用TC来学习C语言
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]

2007-08-30 11:16
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 

To Sister 雨中飞燕:


Test 3: Time Limit Exceed

Cannot pass?

It probably means either the testing data is very
tough, or my algoirthm (using STL) needs to be
optimized. I only cared about AC when I started
practicing ACM.

BTW, which ACM judge system did you use?

Bow,

HJin


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-08-30 12:19
死了都要C
Rank: 4
来 自:四川成都
等 级:贵宾
威 望:13
帖 子:1582
专家分:116
注 册:2006-12-7
收藏
得分:0 
以下是引用雨中飞燕在2007-8-30 11:16:31的发言:

Name: "HJin" Problem ID "38"
Submit Time: 2007/8/30-11:13

G++: Compile Warning:
Line In function `void convert(const std::string&)':
Line 20: warning: comparison between signed and unsigned integer expressions

Test 1: Accepted Time = 0 ms
Test 2: Accepted Time = 10 ms
Test 3: Time Limit Exceed
────────────────
Problem ID 38
Test Result Time Limit Exceed
Total Time Null
Total Memory 280 Kb
Code Length 1373 Bytes

不是PKU的结果,不过是我自己加了数据



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

请大家不要用TC来学习C语言
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]

你上面的那些```数据和英文是什么意思啊```怎么来的啊``
好像是测试之类的``

现在的头像比以前好看```


女施主``我给你``送茶来了```师太``你就从了老衲吧``
代码本天成~~~妙头偶得之```
2007-08-30 12:24
雨中飞燕
Rank: 3Rank: 3
等 级:禁止访问
威 望:8
帖 子:2200
专家分:0
注 册:2007-8-9
收藏
得分:0 
以下是引用HJin在2007-8-30 12:19:24的发言:

To Sister 雨中飞燕:


Test 3: Time Limit Exceed

Cannot pass?

It probably means either the testing data is very
tough, or my algoirthm (using STL) needs to be
optimized. I only cared about AC when I started
practicing ACM.

BTW, which ACM judge system did you use?

Bow,

HJin

这个Judge系统是我自己开发的,第三个Test是数据量较多的一组,
在PKU超过300ms的代码在这里都会TLE

2007-08-30 12:55
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
回复:(雨中飞燕)以下是引用HJin在2007-8-30 12:19:...

Hi 雨中飞燕:

I just stopped by your website and did not find the "submit" button.

Are you judging manually?

HJin


I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-08-30 13:27
雨中飞燕
Rank: 3Rank: 3
等 级:禁止访问
威 望:8
帖 子:2200
专家分:0
注 册:2007-8-9
收藏
得分:0 
In my website, "submit" means reply,
[code]pasted your code here[/code]



by 雨中飞燕 QQ:78803110 QQ讨论群:5305909

请大家不要用TC来学习C语言
C/C++算法习题(OnlineJudge):[url]http://yzfy.org/[/url]
2007-08-30 13:43
HJin
Rank: 6Rank: 6
等 级:贵宾
威 望:27
帖 子:401
专家分:0
注 册:2007-6-9
收藏
得分:0 
suggestion:

1. #define PB_ID 38
2.

These two requirements can be done on the server side. You simply need to test the 1st, 2nd, and last lines of the input stream. If they are not there, you add them.

I am working on a system which has no Chinese input. Please don\'t blame me for typing English.
2007-08-30 13:56
快速回复:OJ1002我哪里错了?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.050207 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved